minor tweaks,optimize code (#2788)

This commit is contained in:
Lanco 2021-08-23 01:32:41 +08:00 committed by GitHub
parent dfc25f91e0
commit 4e7584175d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,8 +102,7 @@ func (r SecureJSON) Render(w http.ResponseWriter) error {
// if the jsonBytes is array values // if the jsonBytes is array values
if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes, if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes,
bytesconv.StringToBytes("]")) { bytesconv.StringToBytes("]")) {
_, err = w.Write(bytesconv.StringToBytes(r.Prefix)) if _, err = w.Write(bytesconv.StringToBytes(r.Prefix)); err != nil {
if err != nil {
return err return err
} }
} }
@ -130,20 +129,19 @@ func (r JsonpJSON) Render(w http.ResponseWriter) (err error) {
} }
callback := template.JSEscapeString(r.Callback) callback := template.JSEscapeString(r.Callback)
_, err = w.Write(bytesconv.StringToBytes(callback)) if _, err = w.Write(bytesconv.StringToBytes(callback)); err != nil {
if err != nil {
return err return err
} }
_, err = w.Write(bytesconv.StringToBytes("("))
if err != nil { if _, err = w.Write(bytesconv.StringToBytes("(")); err != nil {
return err return err
} }
_, err = w.Write(ret)
if err != nil { if _, err = w.Write(ret); err != nil {
return err return err
} }
_, err = w.Write(bytesconv.StringToBytes(");"))
if err != nil { if _, err = w.Write(bytesconv.StringToBytes(");")); err != nil {
return err return err
} }