diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9f6b44 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/define/response.go b/define/response.go new file mode 100644 index 0000000..1ec5a4c --- /dev/null +++ b/define/response.go @@ -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 + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..85dc474 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.zhangdeman.cn/zhangdeman/gin + +go 1.18