mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 01:12:16 +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 {
|
||||
writeContentType(w, jsonContentType)
|
||||
jsonBytes, err := json.Marshal(obj)
|
||||
encoder := json.NewEncoder(w)
|
||||
err := encoder.Encode(&obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w.Write(jsonBytes)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user