gin/define/response.go

90 lines
2.2 KiB
Go
Raw Normal View History

// 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"
// ResponseCodeField 响应状态码字段
ResponseCodeField = "code"
// ResponseMessageField 响应信息字段
ResponseMessageField = "message"
// HandleRequestCostField 处理请求耗时
HandleRequestCostField = "cost"
// ResponseDataField 响应数据字段
ResponseDataField = "data"
// ResponseTraceIDField 响应TraceID字段
ResponseTraceIDField = "trace_id"
// ResponseRequestIDField 响应的请求ID字段
ResponseRequestIDField = "request_id"
)
// 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
}
// 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
}
}