httpclient支持mesh请求 #2

Merged
zhangdeman merged 26 commits from feature/upgrade_httpclient into master 2025-04-01 12:16:20 +08:00
Showing only changes of commit 311f896f0f - Show all commits

View File

@ -1,4 +1,4 @@
// Package httpclient ...
// Package log ...
//
// Description : httpclient ...
//
@ -8,7 +8,9 @@
package log
import (
"context"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/network/httpclient/define"
"go.uber.org/zap"
)
@ -34,16 +36,35 @@ func Get() *zap.Logger {
return logger
}
var buildHttpLogDataFunc BuildHttpLogDataFunc
// BuildHttpLogDataFunc 构建http请求日志数据的方法
type BuildHttpLogDataFunc func(ctx context.Context, reqCfg *define.Request, response *define.Response) []zap.Field
func SetBuildDataFunc(f BuildHttpLogDataFunc) {
buildHttpLogDataFunc = f
}
func GetBuildDataFunc() BuildHttpLogDataFunc {
return buildHttpLogDataFunc
}
// Record 日志记录
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:07 2025/3/31
func Record(logInstance *zap.Logger, level consts.LogLevel, msg string, fields ...zap.Field) {
func Record(ctx context.Context, logInstance *zap.Logger, level consts.LogLevel, msg string, reqCfg *define.Request, response *define.Response) {
if nil == logInstance {
// 未设置日志实例
return
}
buildDataFunc := GetBuildDataFunc()
if nil == buildDataFunc {
// 未设置构建日志数据的方法
return
}
fields := buildDataFunc(ctx, reqCfg, response)
switch level {
case consts.LogLevelDebug:
logInstance.Debug(msg, fields...)
@ -56,5 +77,4 @@ func Record(logInstance *zap.Logger, level consts.LogLevel, msg string, fields .
case consts.LogLevelPanic:
logInstance.Panic(msg, fields...)
}
}