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
1 changed files with 8 additions and 10 deletions

View File

@ -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
}
}
@ -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
}