This commit is contained in:
cdle
2023-06-02 16:52:49 +08:00
parent 985e012f01
commit 8eb0db0dc1
4 changed files with 109 additions and 37 deletions
+2 -8
View File
@@ -3,7 +3,6 @@ package core
import (
"fmt"
"net/http"
"strings"
"github.com/cdle/sillyplus/utils"
"github.com/dop251/goja"
@@ -62,14 +61,9 @@ func (r *Response) Json(ps ...interface{}) *Response {
}
d, err := json.Marshal(data)
f := string(d)
r.status = int(status)
if err == nil {
if strings.Contains(f, `"error"`) {
f = strings.Replace(f, "error", "msg", 1)
if status == 200 {
status = -1
}
}
r.content = strings.Replace(f, "{", fmt.Sprintf(`{"status":%d, `, status), 1)
r.content = f
r.isJson = true
} else {
r.content += fmt.Sprint(data)