feat: response json EscapeHTML
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package response
|
||||
|
||||
import jsoniter "github.com/json-iterator/go"
|
||||
|
||||
var _ Error = (*err)(nil)
|
||||
|
||||
type Error interface {
|
||||
@@ -53,7 +51,7 @@ func (e *err) ToString() string {
|
||||
Data: e.Data,
|
||||
}
|
||||
|
||||
raw, _ := jsoniter.Marshal(err)
|
||||
raw, _ := jsonAPI.Marshal(err)
|
||||
return string(raw)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
var jsonAPI = jsoniter.Config{EscapeHTML: false}.Froze()
|
||||
|
||||
type BaseController struct{}
|
||||
|
||||
func (b *BaseController) Fail(w http.ResponseWriter) {
|
||||
@@ -24,12 +26,12 @@ func (b *BaseController) Out(w http.ResponseWriter, data any, cm Error) {
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_ = jsoniter.NewEncoder(w).Encode(out)
|
||||
_ = jsonAPI.NewEncoder(w).Encode(out)
|
||||
}
|
||||
|
||||
func (b *BaseController) OutPut(w http.ResponseWriter, code int32, data any, msg string) {
|
||||
if code == utils.Ok.Code && !utils.GetConfigBool("encrypt.debug") {
|
||||
jsonData, err := jsoniter.Marshal(data)
|
||||
jsonData, err := jsonAPI.Marshal(data)
|
||||
if err != nil {
|
||||
fmt.Printf("response encrypt: json.Marshal failed: %v\n", err)
|
||||
msg = utils.ErrorEncryptAesError.Msg
|
||||
@@ -52,13 +54,13 @@ func (b *BaseController) OutPut(w http.ResponseWriter, code int32, data any, msg
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_ = jsoniter.NewEncoder(w).Encode(out)
|
||||
_ = jsonAPI.NewEncoder(w).Encode(out)
|
||||
}
|
||||
|
||||
func (b *BaseController) OutPutBack(w http.ResponseWriter, back responseDataBack) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_ = jsoniter.NewEncoder(w).Encode(back)
|
||||
_ = jsonAPI.NewEncoder(w).Encode(back)
|
||||
}
|
||||
|
||||
func (b *BaseController) OutPutDown(w http.ResponseWriter, back responseDataDown) {
|
||||
|
||||
Reference in New Issue
Block a user