Extract a method for writing content type

This commit is contained in:
Filip Figiel 2018-08-17 09:38:18 +02:00
parent f01951917b
commit 2000a13bd1

View File

@ -54,12 +54,16 @@ func WriteJSON(w http.ResponseWriter, obj interface{}) error {
}
func (r PureJSON) Render(w http.ResponseWriter) error {
writeContentType(w, jsonContentType)
r.WriteContentType(w)
encoder := json.NewEncoder(w)
encoder.SetEscapeHTML(false)
return encoder.Encode(r.Data)
}
func (r PureJSON) WriteContentType(w http.ResponseWriter) {
writeContentType(w, jsonContentType)
}
func (r IndentedJSON) Render(w http.ResponseWriter) error {
r.WriteContentType(w)
jsonBytes, err := json.MarshalIndent(r.Data, "", " ")