From 53813826951152f1433d72f3d2e972c7e2c55aa5 Mon Sep 17 00:00:00 2001 From: eeonevision Date: Wed, 27 Nov 2019 18:28:13 +0300 Subject: [PATCH] Returned public WriteJSON method --- render/json.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/render/json.go b/render/json.go index 75dad12356..4e90f783bf 100644 --- a/render/json.go +++ b/render/json.go @@ -63,6 +63,14 @@ func (r JSON) WriteContentType(w http.ResponseWriter) { writeContentType(w, jsonContentType) } +// WriteJSON marshals the given interface object and writes it with custom ContentType. +func WriteJSON(w http.ResponseWriter, obj interface{}) error { + writeContentType(w, jsonContentType) + encoder := json.NewEncoder(w) + err := encoder.Encode(&obj) + return err +} + // Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType. func (r IndentedJSON) Render(w http.ResponseWriter) error { r.WriteContentType(w)