mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 06:42:10 +08:00
Returned public WriteJSON method
This commit is contained in:
parent
ea0b535a8d
commit
5381382695
@ -63,6 +63,14 @@ func (r JSON) WriteContentType(w http.ResponseWriter) {
|
|||||||
writeContentType(w, jsonContentType)
|
writeContentType(w, jsonContentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteJSON marshals the given interface object and writes it with custom ContentType.
|
||||||
|
func WriteJSON(w http.ResponseWriter, obj interface{}) error {
|
||||||
|
writeContentType(w, jsonContentType)
|
||||||
|
encoder := json.NewEncoder(w)
|
||||||
|
err := encoder.Encode(&obj)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType.
|
// Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType.
|
||||||
func (r IndentedJSON) Render(w http.ResponseWriter) error {
|
func (r IndentedJSON) Render(w http.ResponseWriter) error {
|
||||||
r.WriteContentType(w)
|
r.WriteContentType(w)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user