gin/define/response.go

111 lines
3.8 KiB
Go
Raw Normal View History

// Package define ...
//
// Description : define ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-06-25 20:33
package define
2024-07-23 17:09:29 +08:00
import (
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/wrapper"
)
var (
2024-07-23 21:53:00 +08:00
inputHttpHandleConfig = &HttpHandleConfig{}
)
// HttpHandleConfig 请求处理配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:41 2022/6/25
type HttpHandleConfig struct {
2024-07-23 21:34:40 +08:00
RecordRequestDataField string
RecordResponseDataField string
RequestIDField string
TraceIDField string
ResponseCodeField string
ResponseMessageField string
HandleRequestCostField string
ResponseDataField string
ResponseTraceIDField string
StartRequestTimeField string
FinishRequestTimeField string
}
// ConvertDefaultConfig 覆盖默认配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:41 2022/6/25
func ConvertDefaultConfig(cfg *HttpHandleConfig) {
2024-07-23 17:09:29 +08:00
inputHttpHandleConfig = cfg
}
2022-06-25 23:03:46 +08:00
2024-07-23 17:09:29 +08:00
// GetHttpHandleConfig 获取http配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:55 2024/7/23
func GetHttpHandleConfig() *HttpHandleConfig {
return &HttpHandleConfig{
RequestIDField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.RequestIDField == "",
consts.GinRequestIDField,
wrapper.String(inputHttpHandleConfig.RequestIDField),
).Value(),
TraceIDField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.TraceIDField == "",
consts.GinTraceIDField,
wrapper.String(inputHttpHandleConfig.TraceIDField),
).Value(),
ResponseCodeField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.ResponseCodeField == "",
consts.GinResponseCodeField,
wrapper.String(inputHttpHandleConfig.ResponseCodeField),
).Value(),
ResponseMessageField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.ResponseMessageField == "",
consts.GinResponseMessageField,
wrapper.String(inputHttpHandleConfig.ResponseMessageField),
).Value(),
HandleRequestCostField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.HandleRequestCostField == "",
consts.GinHandleRequestCostField,
wrapper.String(inputHttpHandleConfig.HandleRequestCostField),
).Value(),
ResponseDataField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.ResponseDataField == "",
consts.GinResponseDataField,
wrapper.String(inputHttpHandleConfig.ResponseDataField),
).Value(),
ResponseTraceIDField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.ResponseTraceIDField == "",
consts.GinResponseTraceIDField,
wrapper.String(inputHttpHandleConfig.ResponseTraceIDField),
).Value(),
StartRequestTimeField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.StartRequestTimeField == "",
consts.GinStartRequestTimeField,
wrapper.String(inputHttpHandleConfig.StartRequestTimeField),
).Value(),
FinishRequestTimeField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.FinishRequestTimeField == "",
consts.GinFinishRequestTimeField,
wrapper.String(inputHttpHandleConfig.FinishRequestTimeField),
).Value(),
2024-07-23 21:34:40 +08:00
RecordRequestDataField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.RecordRequestDataField == "",
consts.GinRecordRequestDataField,
wrapper.String(inputHttpHandleConfig.RecordRequestDataField),
).Value(),
RecordResponseDataField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.RecordResponseDataField == "",
consts.GinRecordResponseDataField,
wrapper.String(inputHttpHandleConfig.RecordResponseDataField),
).Value(),
2022-06-25 23:03:46 +08:00
}
}