mirror of
https://github.com/gin-gonic/gin.git
synced 2025-12-11 19:47:00 +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.
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if r.Callback == "" {
|
||||
writeContentType(w, jsonContentType)
|
||||
_, err = w.Write(ret)
|
||||
return err
|
||||
}
|
||||
|
||||
r.WriteContentType(w)
|
||||
|
||||
callback := template.JSEscapeString(r.Callback)
|
||||
if _, err = w.Write(bytesconv.StringToBytes(callback)); err != nil {
|
||||
return err
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user