mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
Extract a method for writing content type
This commit is contained in:
parent
f01951917b
commit
2000a13bd1
@ -54,12 +54,16 @@ func WriteJSON(w http.ResponseWriter, obj interface{}) error {
|
||||
}
|
||||
|
||||
func (r PureJSON) Render(w http.ResponseWriter) error {
|
||||
writeContentType(w, jsonContentType)
|
||||
r.WriteContentType(w)
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder.SetEscapeHTML(false)
|
||||
return encoder.Encode(r.Data)
|
||||
}
|
||||
|
||||
func (r PureJSON) WriteContentType(w http.ResponseWriter) {
|
||||
writeContentType(w, jsonContentType)
|
||||
}
|
||||
|
||||
func (r IndentedJSON) Render(w http.ResponseWriter) error {
|
||||
r.WriteContentType(w)
|
||||
jsonBytes, err := json.MarshalIndent(r.Data, "", " ")
|
||||
|
Loading…
x
Reference in New Issue
Block a user