mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
use encode replace json marshal increase json encoder speed
This commit is contained in:
parent
3f27866f80
commit
f3f2da568c
@ -54,11 +54,11 @@ func (r JSON) WriteContentType(w http.ResponseWriter) {
|
|||||||
|
|
||||||
func WriteJSON(w http.ResponseWriter, obj interface{}) error {
|
func WriteJSON(w http.ResponseWriter, obj interface{}) error {
|
||||||
writeContentType(w, jsonContentType)
|
writeContentType(w, jsonContentType)
|
||||||
jsonBytes, err := json.Marshal(obj)
|
encoder := json.NewEncoder(w)
|
||||||
|
err := encoder.Encode(&obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.Write(jsonBytes)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user