Skip to content

Commit

Permalink
minor tweaks,optimize code (gin-gonic#2788)
Browse files Browse the repository at this point in the history
  • Loading branch information
lancoLiu authored Aug 22, 2021
1 parent dfc25f9 commit 4e75841
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions render/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func (r SecureJSON) Render(w http.ResponseWriter) error {
// if the jsonBytes is array values
if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes,
bytesconv.StringToBytes("]")) {
_, err = w.Write(bytesconv.StringToBytes(r.Prefix))
if err != nil {
if _, err = w.Write(bytesconv.StringToBytes(r.Prefix)); err != nil {
return err
}
}
Expand All @@ -130,20 +129,19 @@ func (r JsonpJSON) Render(w http.ResponseWriter) (err error) {
}

callback := template.JSEscapeString(r.Callback)
_, err = w.Write(bytesconv.StringToBytes(callback))
if err != nil {
if _, err = w.Write(bytesconv.StringToBytes(callback)); err != nil {
return err
}
_, err = w.Write(bytesconv.StringToBytes("("))
if err != nil {

if _, err = w.Write(bytesconv.StringToBytes("(")); err != nil {
return err
}
_, err = w.Write(ret)
if err != nil {

if _, err = w.Write(ret); err != nil {
return err
}
_, err = w.Write(bytesconv.StringToBytes(");"))
if err != nil {

if _, err = w.Write(bytesconv.StringToBytes(");")); err != nil {
return err
}

Expand Down

0 comments on commit 4e75841

Please sign in to comment.