Adds supports for custom JSON Content-type

This commit is contained in:
Manu Mtz-Almeida
2015-06-13 04:29:10 +02:00
parent 22f118f3b6
commit a7c957af7d
4 changed files with 23 additions and 6 deletions
+2 -2
View File
@@ -26,7 +26,7 @@ func (r JSON) Render(w http.ResponseWriter) error {
}
func (r IndentedJSON) Render(w http.ResponseWriter) error {
w.Header()["Content-Type"] = jsonContentType
writeContentType(w, jsonContentType)
jsonBytes, err := json.MarshalIndent(r.Data, "", " ")
if err != nil {
return err
@@ -36,6 +36,6 @@ func (r IndentedJSON) Render(w http.ResponseWriter) error {
}
func WriteJSON(w http.ResponseWriter, obj interface{}) error {
w.Header()["Content-Type"] = jsonContentType
writeContentType(w, jsonContentType)
return json.NewEncoder(w).Encode(obj)
}