use encode replace json marshal increase json encoder speed (#1546)

This commit is contained in:
itcloudy
2019-05-22 07:48:50 +08:00
committed by 田欧
parent b1d607a899
commit 0cbf290302
5 changed files with 12 additions and 15 deletions

View File

@ -68,11 +68,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)
jsonBytes, err := json.Marshal(obj)
if err != nil {
return err
}
_, err = w.Write(jsonBytes)
encoder := json.NewEncoder(w)
err := encoder.Encode(&obj)
return err
}