2022-06-25 20:50:42 +08:00
|
|
|
// Package define ...
|
|
|
|
//
|
|
|
|
// Description : define ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2022-06-25 20:33
|
|
|
|
package define
|
|
|
|
|
|
|
|
var (
|
|
|
|
// RequestIDField 请求ID
|
|
|
|
RequestIDField = "request_id"
|
|
|
|
// TraceIDField 追踪ID
|
|
|
|
TraceIDField = "trace_id"
|
2022-06-25 23:03:46 +08:00
|
|
|
// StartRequestTimeField 开始请求时间字段
|
|
|
|
StartRequestTimeField = "start_request_time"
|
2022-07-14 14:15:09 +08:00
|
|
|
// FinishRequestTimeField 完成请求时间
|
|
|
|
FinishRequestTimeField = "finish_request_time"
|
2022-06-25 20:50:42 +08:00
|
|
|
// ResponseCodeField 响应状态码字段
|
|
|
|
ResponseCodeField = "code"
|
|
|
|
// ResponseMessageField 响应信息字段
|
|
|
|
ResponseMessageField = "message"
|
|
|
|
// HandleRequestCostField 处理请求耗时
|
|
|
|
HandleRequestCostField = "cost"
|
|
|
|
// ResponseDataField 响应数据字段
|
|
|
|
ResponseDataField = "data"
|
|
|
|
// ResponseTraceIDField 响应TraceID字段
|
|
|
|
ResponseTraceIDField = "trace_id"
|
|
|
|
// ResponseRequestIDField 响应的请求ID字段
|
|
|
|
ResponseRequestIDField = "request_id"
|
2022-07-14 11:01:06 +08:00
|
|
|
// RecordResponseDataField 记录响应数据到上下文
|
|
|
|
RecordResponseDataField = "pkg_gin_record_response_data"
|
|
|
|
// RecordRequestDataField 记录请求数据到上下文
|
|
|
|
RecordRequestDataField = "pkg_gin_record_request_data"
|
2022-06-25 20:50:42 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// HttpHandleConfig 请求处理配置
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 20:41 2022/6/25
|
|
|
|
type HttpHandleConfig struct {
|
|
|
|
RequestIDField string
|
|
|
|
TraceIDField string
|
|
|
|
ResponseCodeField string
|
|
|
|
ResponseMessageField string
|
|
|
|
HandleRequestCostField string
|
|
|
|
ResponseDataField string
|
|
|
|
ResponseTraceIDField string
|
|
|
|
ResponseRequestIDField string
|
2022-06-25 23:03:46 +08:00
|
|
|
StartRequestTimeField string
|
2022-06-25 20:50:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertDefaultConfig 覆盖默认配置
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 20:41 2022/6/25
|
|
|
|
func ConvertDefaultConfig(cfg *HttpHandleConfig) {
|
|
|
|
if len(cfg.RequestIDField) > 0 {
|
|
|
|
RequestIDField = cfg.ResponseRequestIDField
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.TraceIDField) > 0 {
|
|
|
|
TraceIDField = cfg.TraceIDField
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.ResponseCodeField) > 0 {
|
|
|
|
ResponseCodeField = cfg.ResponseCodeField
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.ResponseMessageField) > 0 {
|
|
|
|
ResponseMessageField = cfg.ResponseMessageField
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.ResponseDataField) > 0 {
|
|
|
|
ResponseDataField = cfg.ResponseDataField
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.ResponseRequestIDField) > 0 {
|
|
|
|
ResponseRequestIDField = cfg.ResponseRequestIDField
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.ResponseTraceIDField) > 0 {
|
|
|
|
ResponseTraceIDField = cfg.ResponseTraceIDField
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.HandleRequestCostField) > 0 {
|
|
|
|
HandleRequestCostField = cfg.HandleRequestCostField
|
|
|
|
}
|
2022-06-25 23:03:46 +08:00
|
|
|
|
|
|
|
if len(cfg.StartRequestTimeField) > 0 {
|
|
|
|
StartRequestTimeField = cfg.StartRequestTimeField
|
|
|
|
}
|
2022-06-25 20:50:42 +08:00
|
|
|
}
|