定义请求与相应的字段,以及暴露必要的覆盖配置方法
This commit is contained in:
parent
291b394101
commit
4fab6362b6
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### Go template
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
*.xlsx
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
.idea
|
||||
.vscode
|
||||
mail_test.go
|
82
define/response.go
Normal file
82
define/response.go
Normal file
@ -0,0 +1,82 @@
|
||||
// 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"
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user