117 lines
4.2 KiB
Go
117 lines
4.2 KiB
Go
// Package define ...
|
|
//
|
|
// Description : define ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 2022-06-25 20:33
|
|
package define
|
|
|
|
import (
|
|
"git.zhangdeman.cn/zhangdeman/consts"
|
|
"git.zhangdeman.cn/zhangdeman/wrapper"
|
|
)
|
|
|
|
var (
|
|
inputHttpHandleConfig = &HttpHandleConfig{}
|
|
)
|
|
|
|
// HttpHandleConfig 请求处理配置
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 20:41 2022/6/25
|
|
type HttpHandleConfig struct {
|
|
RecordRequestDataField string
|
|
RecordResponseDataField string
|
|
RequestIDField string
|
|
TraceIDField string
|
|
ResponseCodeField string
|
|
ResponseMessageField string
|
|
HandleRequestCostField string
|
|
ResponseDataField string
|
|
ResponseTraceIDField string
|
|
StartRequestTimeField string
|
|
FinishRequestTimeField string
|
|
RequestIsSuccessField string // 请求处理是否成功的标识
|
|
}
|
|
|
|
// ConvertDefaultConfig 覆盖默认配置
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 20:41 2022/6/25
|
|
func ConvertDefaultConfig(cfg *HttpHandleConfig) {
|
|
inputHttpHandleConfig = cfg
|
|
}
|
|
|
|
// 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(),
|
|
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(),
|
|
RequestIsSuccessField: wrapper.TernaryOperator.String(
|
|
nil == inputHttpHandleConfig || inputHttpHandleConfig.RequestIsSuccessField == "",
|
|
consts.GinRequestIsSuccessField,
|
|
wrapper.String(inputHttpHandleConfig.RecordResponseDataField),
|
|
).Value(),
|
|
}
|
|
}
|