Update json.go

This commit is contained in:
lihang212010 2020-10-16 14:59:45 +08:00 committed by GitHub
parent 1473b34fd4
commit 4c44b661a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,8 +66,8 @@ func (r JSON) WriteContentType(w http.ResponseWriter) {
// WriteJSON marshals the given interface object and writes it with custom ContentType.
func WriteJSON(w http.ResponseWriter, obj interface{}) error {
writeContentType(w, jsonContentType)
if _, isJson := r.Data.([]byte); isJson {
_, err = w.Write(jsonBytes)
if _, isJson := obj.([]byte); isJson {
_, err := w.Write(obj.([]byte))
return err
}
jsonBytes, err := json.Marshal(obj)