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
|
|
|
|
|
2024-07-23 17:09:29 +08:00
|
|
|
import (
|
|
|
|
"git.zhangdeman.cn/zhangdeman/consts"
|
|
|
|
"git.zhangdeman.cn/zhangdeman/wrapper"
|
|
|
|
)
|
|
|
|
|
2022-06-25 20:50:42 +08:00
|
|
|
var (
|
2024-07-23 21:53:00 +08:00
|
|
|
inputHttpHandleConfig = &HttpHandleConfig{}
|
2022-06-25 20:50:42 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2024-08-17 17:31:11 +08:00
|
|
|
RequestIsSuccessField string // 请求处理是否成功的标识
|
2024-09-24 14:56:03 +08:00
|
|
|
ExtensionOutputField string // 扩展信息对外输出字段
|
|
|
|
EnableExtensionOutput bool
|
2022-06-25 20:50:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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{
|
2024-09-24 15:10:37 +08:00
|
|
|
EnableExtensionOutput: inputHttpHandleConfig.EnableExtensionOutput,
|
2024-07-23 17:09:29 +08:00
|
|
|
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(),
|
2024-08-17 17:31:11 +08:00
|
|
|
RequestIsSuccessField: wrapper.TernaryOperator.String(
|
|
|
|
nil == inputHttpHandleConfig || inputHttpHandleConfig.RequestIsSuccessField == "",
|
|
|
|
consts.GinRequestIsSuccessField,
|
|
|
|
wrapper.String(inputHttpHandleConfig.RecordResponseDataField),
|
|
|
|
).Value(),
|
2024-09-24 14:56:03 +08:00
|
|
|
ExtensionOutputField: wrapper.TernaryOperator.String(
|
|
|
|
nil == inputHttpHandleConfig || inputHttpHandleConfig.ExtensionOutputField == "",
|
|
|
|
consts.GinResponseExtensionField,
|
|
|
|
wrapper.String(inputHttpHandleConfig.RecordResponseDataField),
|
|
|
|
).Value(),
|
2022-06-25 23:03:46 +08:00
|
|
|
}
|
2022-06-25 20:50:42 +08:00
|
|
|
}
|