gin/define/response.go

96 lines
2.5 KiB
Go

// 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"
// StartRequestTimeField 开始请求时间字段
StartRequestTimeField = "start_request_time"
// FinishRequestTimeField 完成请求时间
FinishRequestTimeField = "finish_request_time"
// ResponseCodeField 响应状态码字段
ResponseCodeField = "code"
// ResponseMessageField 响应信息字段
ResponseMessageField = "message"
// HandleRequestCostField 处理请求耗时
HandleRequestCostField = "cost"
// ResponseDataField 响应数据字段
ResponseDataField = "data"
// ResponseTraceIDField 响应TraceID字段
ResponseTraceIDField = "trace_id"
// ResponseRequestIDField 响应的请求ID字段
ResponseRequestIDField = "request_id"
// RecordResponseDataField 记录响应数据到上下文
RecordResponseDataField = "pkg_gin_record_response_data"
// RecordRequestDataField 记录请求数据到上下文
RecordRequestDataField = "pkg_gin_record_request_data"
)
// 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
StartRequestTimeField string
}
// 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
}
if len(cfg.StartRequestTimeField) > 0 {
StartRequestTimeField = cfg.StartRequestTimeField
}
}