From 9c2ad91230d72fe6d661450cc78300ea223ae2bc Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 19 Oct 2020 11:05:36 +0530 Subject: make it better --- vendor/github.com/gin-gonic/gin/render/json.go | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 vendor/github.com/gin-gonic/gin/render/json.go (limited to 'vendor/github.com/gin-gonic/gin/render/json.go') diff --git a/vendor/github.com/gin-gonic/gin/render/json.go b/vendor/github.com/gin-gonic/gin/render/json.go new file mode 100644 index 0000000..32e6058 --- /dev/null +++ b/vendor/github.com/gin-gonic/gin/render/json.go @@ -0,0 +1,41 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package render + +import ( + "encoding/json" + "net/http" +) + +type ( + JSON struct { + Data interface{} + } + + IndentedJSON struct { + Data interface{} + } +) + +var jsonContentType = []string{"application/json; charset=utf-8"} + +func (r JSON) Render(w http.ResponseWriter) error { + return WriteJSON(w, r.Data) +} + +func (r IndentedJSON) Render(w http.ResponseWriter) error { + writeContentType(w, jsonContentType) + jsonBytes, err := json.MarshalIndent(r.Data, "", " ") + if err != nil { + return err + } + w.Write(jsonBytes) + return nil +} + +func WriteJSON(w http.ResponseWriter, obj interface{}) error { + writeContentType(w, jsonContentType) + return json.NewEncoder(w).Encode(obj) +} -- cgit v1.2.3