func WriteJsonContent()

in helpers/helpers.go [14:28]


func WriteJsonContent(content interface{}, w http.ResponseWriter, statusCode int) {
	contentBytes, marshalErr := json.Marshal(content)
	if marshalErr != nil {
		log.Printf("Could not marshal content for json write: %s", marshalErr)
		return
	}

	w.Header().Add("Content-Type", "application/json")
	w.Header().Add("Content-Length", strconv.FormatInt(int64(len(contentBytes)), 10))
	w.WriteHeader(statusCode)
	_, writeErr := w.Write(contentBytes)
	if writeErr != nil {
		log.Printf("Could not write content to HTTP socket: %s", writeErr)
	}
}