bff config to nacos
CI / changes (push) Successful in 2s
CI / docker-bff (push) Successful in 3m7s
CI / docker-product (push) Has been skipped
CI / docker-admin (push) Successful in 3m26s

This commit is contained in:
2026-08-13 16:27:18 +08:00
parent 94e1c6f97d
commit 6c20427b0a
19 changed files with 458 additions and 169 deletions
+20 -26
View File
@@ -2,37 +2,14 @@ package response
import (
"encoding/json"
"fmt"
"net/http"
"pkg.local/utils"
)
type BaseController struct{}
// Ok 成功输出结果 加密
func (b *BaseController) Ok(w http.ResponseWriter, data any) {
isDebug := GetConfigBool("base.is_debug")
if !isDebug {
jsonData, err := json.Marshal(data)
if err != nil {
b.Fail(w)
return
}
encryptKey := GetEncrypt("encrypt.encrypt_key", 15, 28, 18)
res, enErr := Crypto{}.EncryptKey(jsonData, encryptKey)
if enErr != nil {
b.Fail(w)
return
}
b.Out(w, res, OK)
return
}
b.Out(w, data, OK)
}
// Ok2 成功输出结果 不加密
func (b *BaseController) Ok2(w http.ResponseWriter, data any) {
b.Out(w, data, OK)
}
// Fail 基础错误的输出结果
func (b *BaseController) Fail(w http.ResponseWriter) {
b.Out(w, nil, Fail)
@@ -54,6 +31,23 @@ func (b *BaseController) Out(w http.ResponseWriter, data any, cm Error) {
}
func (b *BaseController) OutPut(w http.ResponseWriter, code int32, data any, msg string) {
if code == utils.Ok.Code && !utils.GetConfigBool("encrypt.debug") {
jsonData, err := json.Marshal(data)
if err != nil {
msg = utils.ErrorEncryptAesError.Msg
code = utils.ErrorEncryptAesError.Code
} else {
res, enErr := utils.Crypto{}.Encrypt(jsonData)
fmt.Printf("res: %v\n", res)
if enErr != nil {
msg = utils.ErrorEncryptAesError.Msg
code = utils.ErrorEncryptAesError.Code
} else {
data = res
}
}
}
// 复制一份,避免并发请求改到包级 OK/Fail 单例
out := NewError(int(code), msg).WithData(data)