回调
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 30s
CI / admin (push) Successful in 22s
CI / bff (push) Successful in 39s
CI / chore (push) Successful in 20s
CI / equipment (push) Successful in 19s
CI / express (push) Successful in 17s
CI / product (push) Successful in 16s
CI / record (push) Successful in 17s
CI / sale (push) Successful in 16s
CI / task (push) Successful in 16s
CI / user (push) Successful in 17s
CI / wecom (push) Successful in 18s
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 30s
CI / admin (push) Successful in 22s
CI / bff (push) Successful in 39s
CI / chore (push) Successful in 20s
CI / equipment (push) Successful in 19s
CI / express (push) Successful in 17s
CI / product (push) Successful in 16s
CI / record (push) Successful in 17s
CI / sale (push) Successful in 16s
CI / task (push) Successful in 16s
CI / user (push) Successful in 17s
CI / wecom (push) Successful in 18s
This commit is contained in:
+6
-20
@@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
@@ -10,12 +9,6 @@ import (
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
CtxCallbackRawBody string = "callback_raw_body"
|
||||
CtxCallbackHeaders string = "callback_headers"
|
||||
CtxCallbackErr string = "callback_read_err"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
ID int64
|
||||
Name string
|
||||
@@ -38,11 +31,6 @@ type UserInfo struct {
|
||||
Valid bool
|
||||
}
|
||||
|
||||
type HeaderAndBody struct {
|
||||
Header http.Header
|
||||
Body []byte
|
||||
}
|
||||
|
||||
func firstMD(md metadata.MD, keys ...string) string {
|
||||
for _, key := range keys {
|
||||
vals := md.Get(key)
|
||||
@@ -122,13 +110,11 @@ func GetUserFromCtx(ctx context.Context) UserInfo {
|
||||
return userInfo
|
||||
}
|
||||
|
||||
// GetHeaderAndBody 只从ctx拿数据,不写http响应,Err交给handler处理
|
||||
func GetHeaderAndBody(ctx context.Context) HeaderAndBody {
|
||||
rawBody, _ := ctx.Value(CtxCallbackRawBody).([]byte)
|
||||
headers, _ := ctx.Value(CtxCallbackHeaders).(http.Header)
|
||||
|
||||
return HeaderAndBody{
|
||||
Header: headers,
|
||||
Body: rawBody,
|
||||
// GetBody 只从ctx拿数据,不写http响应,Err交给handler处理
|
||||
func GetBody(ctx context.Context) string {
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
if !ok {
|
||||
return StringEmpty
|
||||
}
|
||||
return firstMD(md, "x-raw-body")
|
||||
}
|
||||
|
||||
+7
-6
@@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/xuri/excelize/v2"
|
||||
@@ -245,7 +246,7 @@ func RoundMoney(amount float64) float64 {
|
||||
func Decrypt(str string) (string, Error) {
|
||||
str, err := Crypto{}.AESDecryptECB(str)
|
||||
if err != nil {
|
||||
Logger.Error("decrypt str error", str, err)
|
||||
logx.Error("decrypt str error", str, err)
|
||||
return str, err
|
||||
}
|
||||
|
||||
@@ -259,7 +260,7 @@ func DecryptMobile(mobile string) string {
|
||||
|
||||
mobile, err := Decrypt(mobile)
|
||||
if err != nil {
|
||||
Logger.Error("decrypt mobile error", mobile, err)
|
||||
logx.Error("decrypt mobile error", mobile, err)
|
||||
return mobile
|
||||
}
|
||||
|
||||
@@ -488,12 +489,12 @@ func Unique(s []string) []string {
|
||||
func MapToStruct(data map[string]interface{}, target interface{}) error {
|
||||
jsonData, err := jsoniter.Marshal(data) // 将 map 转换为 JSON 字节切片
|
||||
if err != nil {
|
||||
Logger.Error("Error marshalling map to JSON:", err)
|
||||
logx.Error("Error marshalling map to JSON:", err)
|
||||
return err
|
||||
}
|
||||
err = jsoniter.Unmarshal(jsonData, &target) // 将 JSON 字节切片解析到结构体中
|
||||
if err != nil {
|
||||
Logger.Error("Error unmarshalling JSON:", err)
|
||||
logx.Error("Error unmarshalling JSON:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -503,14 +504,14 @@ func MapToStruct(data map[string]interface{}, target interface{}) error {
|
||||
func JsonStringToStruct(jsonStr string, v interface{}) bool {
|
||||
// 1. 校验入参:确保v是指针类型(否则json.Unmarshal无法工作)
|
||||
if v == nil {
|
||||
Logger.Error("传入的结构体指针不能为nil")
|
||||
logx.Error("传入的结构体指针不能为nil")
|
||||
return false
|
||||
}
|
||||
|
||||
// 2. 将JSON字符串转为字节数组,执行解析
|
||||
err := jsoniter.Unmarshal([]byte(jsonStr), v)
|
||||
if err != nil {
|
||||
Logger.Error("JSON解析失败: ", err, jsonStr)
|
||||
logx.Error("JSON解析失败: ", err, jsonStr)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user