chore(vendor): upgrade gin repo (#249)

This commit is contained in:
Bo-Yi Wu
2017-07-14 22:23:57 -05:00
committed by GitHub
parent 02f0390d4d
commit 6a64b42ab0
69 changed files with 8967 additions and 298 deletions

View File

@@ -5,19 +5,28 @@
package render
import (
"encoding/json"
"bytes"
"net/http"
"github.com/json-iterator/go"
)
type (
JSON struct {
Data interface{}
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
IndentedJSON struct {
Data interface{}
}
)
type JSON struct {
Data interface{}
}
type IndentedJSON struct {
Data interface{}
}
type SecureJSON struct {
Prefix string
Data interface{}
}
type SecureJSONPrefix string
var jsonContentType = []string{"application/json; charset=utf-8"}
@@ -55,3 +64,21 @@ func (r IndentedJSON) Render(w http.ResponseWriter) error {
func (r IndentedJSON) WriteContentType(w http.ResponseWriter) {
writeContentType(w, jsonContentType)
}
func (r SecureJSON) Render(w http.ResponseWriter) error {
r.WriteContentType(w)
jsonBytes, err := json.Marshal(r.Data)
if err != nil {
return err
}
// if the jsonBytes is array values
if bytes.HasPrefix(jsonBytes, []byte("[")) && bytes.HasSuffix(jsonBytes, []byte("]")) {
w.Write([]byte(r.Prefix))
}
w.Write(jsonBytes)
return nil
}
func (r SecureJSON) WriteContentType(w http.ResponseWriter) {
writeContentType(w, jsonContentType)
}