mirror of
https://github.com/gin-gonic/gin.git
synced 2025-12-13 13:12:17 +08:00
refactor(render): use WriteJSON when JsonpJson.Callback is empty
This commit is contained in:
parent
b7afe5a6af
commit
a14cf7c08d
@ -115,19 +115,17 @@ func (r SecureJSON) WriteContentType(w http.ResponseWriter) {
|
|||||||
|
|
||||||
// Render (JsonpJSON) marshals the given interface object and writes it and its callback with custom ContentType.
|
// Render (JsonpJSON) marshals the given interface object and writes it and its callback with custom ContentType.
|
||||||
func (r JsonpJSON) Render(w http.ResponseWriter) (err error) {
|
func (r JsonpJSON) Render(w http.ResponseWriter) (err error) {
|
||||||
|
if r.Callback == "" {
|
||||||
|
return WriteJSON(w, r.Data)
|
||||||
|
}
|
||||||
|
|
||||||
|
r.WriteContentType(w)
|
||||||
|
|
||||||
ret, err := json.API.Marshal(r.Data)
|
ret, err := json.API.Marshal(r.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Callback == "" {
|
|
||||||
writeContentType(w, jsonContentType)
|
|
||||||
_, err = w.Write(ret)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.WriteContentType(w)
|
|
||||||
|
|
||||||
callback := template.JSEscapeString(r.Callback)
|
callback := template.JSEscapeString(r.Callback)
|
||||||
if _, err = w.Write(bytesconv.StringToBytes(callback)); err != nil {
|
if _, err = w.Write(bytesconv.StringToBytes(callback)); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user