修复parse_body相关BUG
This commit is contained in:
parent
2aa8e86917
commit
927870b11a
@ -8,6 +8,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/gin/request/parse_body"
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
@ -97,12 +98,14 @@ func LogRequest(cfg *AccessConfig) gin.HandlerFunc {
|
||||
}
|
||||
startRequestTime := request.WrapperHandle.GetCtxIntData(ctx, handleConfig.StartRequestTimeField, 0)
|
||||
// 记录请求日志
|
||||
logData := logger.NewLogData(ctx, consts.LogTypeRequest, "", map[string]any{
|
||||
data := map[string]any{
|
||||
handleConfig.StartRequestTimeField: startRequestTime, // 开始请求时间
|
||||
"request_header": getLogRequestHeader(ctx, cfg), // 请求header
|
||||
"request_query": request.WrapperHandle.ParseQuery(ctx), // 获取请求query
|
||||
"request_body": request.WrapperHandle.ParseBody(ctx), // 请求body
|
||||
})
|
||||
"request_body": map[string]any{}, // 请求body
|
||||
}
|
||||
data["request_body"], _ = parse_body.ExecuteForMap(ctx)
|
||||
logData := logger.NewLogData(ctx, consts.LogTypeRequest, "", data)
|
||||
cfg.Logger.Info("接口请求日志记录", logger.ZapLogDataList(logData)...)
|
||||
ctx.Next()
|
||||
// 结束时间
|
||||
|
@ -46,7 +46,7 @@ func Register(requestType string, adaptor abstract.RequestBodyParseAdaptor) {
|
||||
func Execute(ctx *gin.Context, receiver any) ([]byte, error) {
|
||||
contentType := strings.ToLower(strings.ReplaceAll(ctx.ContentType(), " ", ""))
|
||||
if len(contentType) == 0 {
|
||||
return nil, errors.New("content_type is empty")
|
||||
return []byte("{}"), nil
|
||||
}
|
||||
// 裁剪出真实的类型,之所以截取,是因为 content_type 中可能还包含编码信息, 如 : application/json;chaset=utf8
|
||||
contentTypeArr := strings.Split(contentType, ";")
|
||||
|
@ -141,13 +141,8 @@ func (wh *wrapperHandle) GetDomain(ctx *gin.Context) string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:25 2024/7/26
|
||||
func (wh *wrapperHandle) ParseBody(ctx *gin.Context) map[string]any {
|
||||
body := map[string]any{}
|
||||
if _, err := parse_body.Execute(ctx, &body); nil != err {
|
||||
return map[string]any{}
|
||||
}
|
||||
|
||||
return body
|
||||
func (wh *wrapperHandle) ParseBody(ctx *gin.Context) (map[string]any, error) {
|
||||
return parse_body.ExecuteForMap(ctx)
|
||||
}
|
||||
|
||||
// GetResponseBody 获取响应body
|
||||
|
Loading…
x
Reference in New Issue
Block a user