5 Commits

24 changed files with 902 additions and 413 deletions

View File

@ -1,68 +0,0 @@
// Package define ...
//
// Description : define ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-04-12 20:57
package define
import (
"fmt"
"strings"
"time"
networkUtil "git.zhangdeman.cn/zhangdeman/network/util"
"git.zhangdeman.cn/zhangdeman/wrapper"
"git.zhangdeman.cn/zhangdeman/trace"
"github.com/gin-gonic/gin"
)
type Context struct {
Context *gin.Context // 继承 gin context
Trace *trace.Runtime // trace 实例
TraceID string
RequestID string
RequestTime time.Time
}
// NewContext 创建context
func NewContext(ginCtx *gin.Context) *Context {
existCtx, exist := ginCtx.Get(CustomContextKey)
if exist && existCtx != nil {
if c, ok := existCtx.(*Context); ok {
return c
}
}
traceID := fmt.Sprintf(
"%v-%v-%v-%v",
time.Now().UnixNano()/1e6,
strings.ReplaceAll(networkUtil.IP.GetHostIP(), ".", ""),
strings.ReplaceAll(networkUtil.IP.GetRemoteIP(ginCtx.Request), ".", ""),
wrapper.StringFromRandom(32, "").Md5().Value,
)
getRequestID := func(ctx *gin.Context, traceID string) string {
requestID := ctx.GetHeader("X-Forward-Request-Id")
if len(requestID) > 0 {
return requestID
}
if len(traceID) > 0 {
return traceID
}
return traceID
}
ctx := &Context{
Context: ginCtx,
Trace: trace.NewRuntime(traceID, 1),
TraceID: traceID,
RequestID: getRequestID(ginCtx, traceID),
RequestTime: time.Now(),
}
httpHandleConfig := GetHttpHandleConfig()
ginCtx.Set(CustomContextKey, ctx)
ginCtx.Set(httpHandleConfig.TraceIDField, traceID)
ginCtx.Set(httpHandleConfig.RequestIDField, ctx.RequestID)
ginCtx.Set(httpHandleConfig.StartRequestTimeField, ctx.RequestTime.UnixMilli())
return ctx
}

View File

@ -4,9 +4,9 @@
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-04-12 20:18
// Date : 2025-03-10 14:38
package define
const (
CustomContextKey = "_CUSTOM_CONTEXT" // 自定义context
GinWrapperContextKey = "GIN_WRAPPER_CONTEXT"
)

View File

@ -146,10 +146,3 @@ func (logic *LogicAfterResponse) AddFailureHook(f func()) {
defer logic.Lock.Unlock()
logic.FailureHookFuncList = append(logic.FailureHookFuncList, f)
}
// ResponseOption 响应的可用选项
type ResponseOption struct {
ContentType string `json:"content_type"` // 响应的contentType
Extension map[string]any `json:"extension"` // 扩展数据
XmlName string `json:"xml_name"` // 以xml文件格式响应数据时, Xml文件名(根节点)
}

62
go.mod
View File

@ -1,24 +1,23 @@
module git.zhangdeman.cn/zhangdeman/gin
go 1.24.1
go 1.23.0
toolchain go1.24.2
toolchain go1.24.0
require (
git.zhangdeman.cn/gateway/api-doc v0.0.0-20250528130517-e02098e64392
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995
git.zhangdeman.cn/zhangdeman/dynamic-struct v0.0.0-20250429065800-fc340b9417cf
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab
git.zhangdeman.cn/zhangdeman/graceful v0.0.0-20250529070945-92833db6f3a4
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20250427065227-163236205af5
git.zhangdeman.cn/zhangdeman/network v0.0.0-20250509030820-7b1a36a7c38c
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250412104923-c1ecb1bfe8d5
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250321102712-1cbfbe959740
github.com/gin-contrib/pprof v1.5.3
github.com/gin-gonic/gin v1.10.1
github.com/go-playground/validator/v10 v10.26.0
git.zhangdeman.cn/gateway/api-doc v0.0.0-20250220105101-71d6db967dc5
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250227040546-863c03f34bb8
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250207091724-ca151fbc1f06
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20241125083316-eab7bab9d7ad
git.zhangdeman.cn/zhangdeman/network v0.0.0-20230925112156-f0eb86dd2442
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241223084948-de2e49144fcd
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20231220041950-807f3d74a6fa
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250124091620-c757e551a8c9
github.com/gin-contrib/pprof v1.5.2
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.25.0
github.com/mcuadros/go-defaults v1.2.0
github.com/sbabiv/xml2map v1.2.1
go.uber.org/zap v1.27.0
)
@ -28,20 +27,20 @@ require (
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 // indirect
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e // indirect
git.zhangdeman.cn/zhangdeman/websocket v0.0.0-20241125101541-c5ea194c9c1e // indirect
github.com/BurntSushi/toml v1.5.0 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
github.com/bytedance/sonic v1.13.3 // indirect
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/bytedance/sonic v1.12.9 // indirect
github.com/bytedance/sonic/loader v0.2.3 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 // indirect
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gin-contrib/sse v1.0.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-webtools/knife4go v1.0.4 // indirect
@ -60,9 +59,8 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mozillazg/go-pinyin v0.20.0 // indirect
github.com/mssola/user_agent v0.6.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sbabiv/xml2map v1.2.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/gin-swagger v1.6.0 // indirect
@ -71,15 +69,15 @@ require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.0 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.18.0 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/net v0.41.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.26.0 // indirect
golang.org/x/tools v0.33.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
golang.org/x/arch v0.14.0 // indirect
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/tools v0.30.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

136
go.sum
View File

@ -1,44 +1,40 @@
git.zhangdeman.cn/gateway/api-doc v0.0.0-20250528130517-e02098e64392 h1:1HALMZC54/krtdGKnRlhATMzCT5sZdvgVIxt4zZIrTk=
git.zhangdeman.cn/gateway/api-doc v0.0.0-20250528130517-e02098e64392/go.mod h1:ypwNuZTQHxynZwm+l5Z8ZYFd5YrLrwnSWy+FxtXLqJw=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995 h1:LmPRAf0AsxRVFPibdpZR89ajlsz8hof2IvMMyTqiEq4=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
git.zhangdeman.cn/zhangdeman/dynamic-struct v0.0.0-20250429065800-fc340b9417cf h1:xCPM3U6i62UvLo9VNvDP45Ue3dPl7ratHu1rSEJRE2k=
git.zhangdeman.cn/zhangdeman/dynamic-struct v0.0.0-20250429065800-fc340b9417cf/go.mod h1:onY+qrB+Uwfuv75JlgHlGdkirAfYcINrvCashtVoBX0=
git.zhangdeman.cn/gateway/api-doc v0.0.0-20250220105101-71d6db967dc5 h1:UV2+nD9HQLbRt+vY98gwPtkd+M8fbfffl7nb4Mkymmc=
git.zhangdeman.cn/gateway/api-doc v0.0.0-20250220105101-71d6db967dc5/go.mod h1:oNTwnepzW09RNfIQCpgmbiayTKLvGx2XP92esfkxv98=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250227040546-863c03f34bb8 h1:VEifPc+vkpEQoX9rj7zxmT1m+IA81XjOxe7+Z1aqWNM=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250227040546-863c03f34bb8/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda h1:bMD6r9gjRy7cO+T4zRQVYAesgIblBdTnhzT1vN5wjvI=
git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda/go.mod h1:dT0rmHcJ9Z9IqWeMIt7YzR88nKkNV2V3dfG0j9Q6lK0=
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241101082529-28a6c68e38a4 h1:s6d4b6yY+NaK1AzoBD1pxqsuygEHQz0Oie86c45geDw=
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241101082529-28a6c68e38a4/go.mod h1:V4Dfg1v/JVIZGEKCm6/aehs8hK+Xow1dkL1yiQymXlQ=
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab h1:O0XaAKKb8qrjcjewonmKfnRsMFoCfJF+tUv6RfhRe94=
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab/go.mod h1:Voc8J4ordx7nuMWpgACXXZULQy7ZIuBzcEIoS8VnDIw=
git.zhangdeman.cn/zhangdeman/graceful v0.0.0-20250529070945-92833db6f3a4 h1:d1B3IXRitiMlY5ssEWRa//RQD24SqRPk/bCpL4/WyOA=
git.zhangdeman.cn/zhangdeman/graceful v0.0.0-20250529070945-92833db6f3a4/go.mod h1:faaKb5d5tz3NmQQ+NrTnBDa1G/tN9/CVuKun1V4WBIE=
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20250427065227-163236205af5 h1:e3N+ODeTBwBOQ4iIzXm9gO3X6Htgc/YmPBImSk7o2mw=
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20250427065227-163236205af5/go.mod h1:lTxYyi7IodBefXSdSZwPFs3Izggg5Wxa2RkHlFVwKLg=
git.zhangdeman.cn/zhangdeman/network v0.0.0-20250509030820-7b1a36a7c38c h1:4Yn7U1TkurpNizrjbIyJDYTRSlD4zp1ypkREyCSBKIM=
git.zhangdeman.cn/zhangdeman/network v0.0.0-20250509030820-7b1a36a7c38c/go.mod h1:uRg3BnUimmrJiv8N61P6Ir4Im2EqxXZe62m4WBw3sec=
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250207091724-ca151fbc1f06 h1:XsjGMkBCi93h56oCg5Lrz5zVpUxify/CQVhQU9+qLWM=
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250207091724-ca151fbc1f06/go.mod h1:Voc8J4ordx7nuMWpgACXXZULQy7ZIuBzcEIoS8VnDIw=
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20241125083316-eab7bab9d7ad h1:6BI3QiDI64SlER1006UJbTJyOCXxB8KCmCK+Kr7FzQo=
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20241125083316-eab7bab9d7ad/go.mod h1:+jPQTyCEQqMWhq4p1LowQWq15emisON+++87ArTgwNA=
git.zhangdeman.cn/zhangdeman/network v0.0.0-20230925112156-f0eb86dd2442 h1:1eBf0C0gdpBQOqjTK3UCw/mwzQ/SCodx3iTQtidx9eE=
git.zhangdeman.cn/zhangdeman/network v0.0.0-20230925112156-f0eb86dd2442/go.mod h1:hFYWiS+ExIuJJJdwHWy4P3pVHbd/0mpv53qlbhDNdTI=
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y=
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9 h1:/GLQaFoLb+ciHOtAS2BIyPNnf4O5ME3AC5PUaJY9kfs=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9/go.mod h1:ABJ655C5QenQNOzf7LjCe4sSB52CXvaWLX2Zg4uwDJY=
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250412104923-c1ecb1bfe8d5 h1:dD1Q/MIrRmIhKqfYPH+y167ca9CKwTPuQt3c1hXWGJ8=
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250412104923-c1ecb1bfe8d5/go.mod h1:PB486NC82nuvn5yi+U2i48ogX/9EAETWAHd8O9TwY9k=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241223084948-de2e49144fcd h1:q7GG14qgXKB4MEXQFOe7/UYebsqMfPaSX80TcPdOosI=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241223084948-de2e49144fcd/go.mod h1:+D6uPSljwHywjVY5WSBY4TRVMj26TN5f5cFGEYMldjs=
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20231220041950-807f3d74a6fa h1:2bZ9VmQF0pIZ+scnN3UuGoXjjKhccnwfIL779QGZArY=
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20231220041950-807f3d74a6fa/go.mod h1:Bta0kzamTWqBIcc6robGAl/iRuyCFbzy45VGbG8L+7Y=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
git.zhangdeman.cn/zhangdeman/websocket v0.0.0-20241125101541-c5ea194c9c1e h1:YE2Gi+M03UDImIpWa3I7jzSesyfu2RL8x/4ONs5v0oE=
git.zhangdeman.cn/zhangdeman/websocket v0.0.0-20241125101541-c5ea194c9c1e/go.mod h1:L/7JugxKZL3JP9JP/XDvPAPz0FQXG1u181Su1+u/d1c=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250321102712-1cbfbe959740 h1:zPUoylfJTbc0EcxW+NEzOTBmoeFZ2I/rLFBnEzxb4Wk=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250321102712-1cbfbe959740/go.mod h1:1ct92dbVc49pmXusA/iGfcQUJzcYmJ+cjAhgc3sDv1I=
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250124091620-c757e551a8c9 h1:yF770WIDNwyiKL0nwmBGmjZvNCLXtHQL4xJyffPjTMU=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250124091620-c757e551a8c9/go.mod h1:I76wxEsWq7KnMQ84elpwTjEqq4I49QFw60tp5h7iGBs=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
github.com/bytedance/sonic v1.13.3 h1:MS8gmaH16Gtirygw7jV91pDCN33NyMrPbN7qiYhEsF0=
github.com/bytedance/sonic v1.13.3/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
github.com/bytedance/sonic v1.12.9 h1:Od1BvK55NnewtGaJsTDeAOSnLVO2BTSLOe0+ooKokmQ=
github.com/bytedance/sonic v1.12.9/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/bytedance/sonic/loader v0.2.3 h1:yctD0Q3v2NOGfSWPLPvG2ggA2kV6TS6s4wioyEqssH0=
github.com/bytedance/sonic/loader v0.2.3/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
@ -47,45 +43,43 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU=
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1/go.mod h1:+hnT3ywWDTAFrW5aE+u2Sa/wT555ZqwoCS+pk3p6ry4=
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
github.com/gin-contrib/pprof v1.5.3 h1:Bj5SxJ3kQDVez/s/+f9+meedJIqLS+xlkIVDe/lcvgM=
github.com/gin-contrib/pprof v1.5.3/go.mod h1:0+LQSZ4SLO0B6+2n6JBzaEygpTBxe/nI+YEYpfQQ6xY=
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/gin-contrib/pprof v1.5.2 h1:Kcq5W2bA2PBcVtF0MqkQjpvCpwJr+pd7zxcQh2csg7E=
github.com/gin-contrib/pprof v1.5.2/go.mod h1:a1W4CDXwAPm2zql2AKdnT7OVCJdV/oFPhJXVOrDs5Ns=
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-openapi/jsonpointer v0.21.1 h1:whnzv/pNXtK2FbX/W9yJfRmE2gsmkfahjMKB0fZvcic=
github.com/go-openapi/jsonpointer v0.21.1/go.mod h1:50I1STOfbY1ycR8jGz8DaMeLCdXiI6aDteEdRNNzpdk=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU=
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=
github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
github.com/go-webtools/knife4go v1.0.4 h1:p32SApmM0sx2/Y5p0QfeaGv5KD96R1mj2CaHdyH8jy8=
github.com/go-webtools/knife4go v1.0.4/go.mod h1:trOlXN1tqBJ7R44sHON3exGvzCwjbsVriIHEenry3d8=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg=
@ -94,8 +88,6 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
@ -122,6 +114,8 @@ github.com/mcuadros/go-defaults v1.2.0 h1:FODb8WSf0uGaY8elWJAkoLL0Ri6AlZ1bFlenk5
github.com/mcuadros/go-defaults v1.2.0/go.mod h1:WEZtHEVIGYVDqkKSWBdWKUVdRyKlMfulPaGDWIVeCWY=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@ -132,8 +126,8 @@ github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6
github.com/mssola/user_agent v0.6.0 h1:uwPR4rtWlCHRFyyP9u2KOV0u8iQXmS7Z7feTrstQwk4=
github.com/mssola/user_agent v0.6.0/go.mod h1:TTPno8LPY3wAIEKRpAtkdMT0f8SE24pLRGPahjCH4uw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -142,20 +136,18 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/sbabiv/xml2map v1.2.1 h1:1lT7t0hhUvXZCkdxqtq4n8/ZCnwLWGq4rDuDv5XOoFE=
github.com/sbabiv/xml2map v1.2.1/go.mod h1:2TPoAfcaM7+Sd4iriPvzyntb2mx7GY+kkQpB/GQa/eo=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE=
@ -173,8 +165,8 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
@ -182,25 +174,25 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/arch v0.18.0 h1:WN9poc33zL4AzGxqf8VtpKUnGvMi8O9lhNyBMF/85qc=
golang.org/x/arch v0.18.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
golang.org/x/arch v0.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4=
golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -208,8 +200,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@ -217,18 +209,18 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=

View File

@ -8,7 +8,6 @@
package middleware
import (
"git.zhangdeman.cn/zhangdeman/gin/request/parse_body"
"strings"
"git.zhangdeman.cn/zhangdeman/consts"
@ -98,14 +97,12 @@ func LogRequest(cfg *AccessConfig) gin.HandlerFunc {
}
startRequestTime := request.WrapperHandle.GetCtxIntData(ctx, handleConfig.StartRequestTimeField, 0)
// 记录请求日志
data := map[string]any{
logData := logger.NewLogData(ctx, consts.LogTypeRequest, "", map[string]any{
handleConfig.StartRequestTimeField: startRequestTime, // 开始请求时间
"request_header": getLogRequestHeader(ctx, cfg), // 请求header
"request_query": request.WrapperHandle.ParseQuery(ctx), // 获取请求query
"request_body": map[string]any{}, // 请求body
}
data["request_body"], _ = parse_body.ExecuteForMap(ctx)
logData := logger.NewLogData(ctx, consts.LogTypeRequest, "", data)
"request_body": request.WrapperHandle.ParseBody(ctx), // 请求body
})
cfg.Logger.Info("接口请求日志记录", logger.ZapLogDataList(logData)...)
ctx.Next()
// 结束时间

View File

@ -7,12 +7,20 @@
// Date : 2024-10-22 16:38
package abstract
import (
"github.com/gin-gonic/gin"
)
// RequestBodyParseAdaptor 解析请求body的接口适配器约束
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:39 2024/10/22
type RequestBodyParseAdaptor interface {
// Parse 解析Body数据解析结果会反序列化至 receiver , 同时, 会以 map 结构返回
Parse(ctx *gin.Context, receiver any) ([]byte, error)
// Unmarshal 自定义反序列化的方法, 为 nil 则使用内置的序列化方式
Unmarshal(sourceData []byte, receiver any) error
Unmarshal() func(sourceData []byte, receiver any) error
// ContentType 当前适配器用与解析何种type
ContentType() string
}

200
request/context.go Normal file
View File

@ -0,0 +1,200 @@
// Package request ...
//
// Description : request ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-02-28 11:45
package request
import (
"fmt"
networkUtil "git.zhangdeman.cn/zhangdeman/network/util"
"git.zhangdeman.cn/zhangdeman/trace"
"git.zhangdeman.cn/zhangdeman/wrapper"
"github.com/gin-gonic/gin"
"os"
"strings"
"sync"
"time"
)
// getTraceID 生成traceID
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 23:12 2022/6/25
func getTraceID(ctx *gin.Context) string {
hostname, _ := os.Hostname()
if hostname != "" {
hostname = "unknown"
}
return fmt.Sprintf(
"%v-%v-%v-%v-%v",
time.Now().UnixNano()/1e6,
strings.ReplaceAll(networkUtil.IP.GetHostIP(), ".", ""),
strings.ReplaceAll(hostname, ".", ""),
strings.ReplaceAll(networkUtil.IP.GetRemoteIP(ctx.Request), ".", ""),
wrapper.StringFromRandom(32, "").Md5().Value,
)
}
// getRequestID 生成requestID
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 23:12 2022/6/25
func getRequestID(ctx *gin.Context, traceID string) string {
requestID := ctx.GetHeader("X-Forward-Request-Id")
if len(requestID) > 0 {
return requestID
}
if len(traceID) > 0 {
return traceID
}
return getTraceID(ctx)
}
// NewContext 获取context实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:01 2025/2/28
func NewContext(ginContext *gin.Context) *Context {
// 生成traceID
traceID := getRequestID(ginContext, "")
hostname, _ := os.Hostname()
return &Context{
Context: ginContext,
StartRequestTime: time.Now(),
FinishRequestTime: time.Unix(0, 0),
HandlerAfterResponse: make([]gin.HandlerFunc, 0),
customData: make(map[string]any),
Hostname: hostname,
HostIp: networkUtil.IP.GetHostIP(),
customLock: &sync.RWMutex{},
TraceID: traceID,
Trace: trace.NewRuntime(traceID, 0),
}
}
// Context 请求上下文信息, 对 ctx *gin.Context的二次包装
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:45 2025/2/28
type Context struct {
*gin.Context `json:"-"`
StartRequestTime time.Time `json:"start_request_time"` // 开始请求时间(全局)
FinishRequestTime time.Time `json:"finish_request_time"` // 结束请求时间(全局)
TraceID string `json:"trace_id"` // 请求trace_id
ParentAppName string `json:"parent_app_name"` // 父级应用名称
HandlerAfterResponse []gin.HandlerFunc `json:"-"` // 响应数据之后需要执行的逻辑
Hostname string `json:"hostname"` // 服务器名称
HostIp string `json:"host_ip"` // 服务器IP
customData map[string]any `json:"-"` // 业务上下文自定义数据, 可以合 ginCtx.Value 作区分
customLock *sync.RWMutex `json:"-"` // 数据锁
Trace *trace.Runtime `json:"-"` // 追踪实例
}
// SetCustom 设置数据
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:58 2025/2/28
func (ctx *Context) SetCustom(key string, val any) {
ctx.customLock.Lock()
defer ctx.customLock.Unlock()
if nil == ctx.customData {
ctx.customData = make(map[string]any)
}
ctx.Set(key, val)
ctx.customData[key] = val
}
// customDataValue 获取customData
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:03 2025/2/28
func (ctx *Context) customDataValue(key string) any {
ctx.customLock.RLock()
defer ctx.customLock.RUnlock()
if val, exist := ctx.customData[key]; exist {
return val
} else {
return ctx.Value(key)
}
}
// customDataExist 判断
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:04 2025/2/28
func (ctx *Context) customDataExist(key string) any {
ctx.customLock.RLock()
defer ctx.customLock.RUnlock()
_, exist := ctx.customData[key]
return exist
}
// customDataAppend 向数组数据中追加元素
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:07 2025/2/28
func (ctx *Context) customDataAppend(key string, appendValue any) {
ctx.customLock.Lock()
defer ctx.customLock.Unlock()
val, exist := ctx.customData[key]
if !exist || nil == val {
ctx.customData[key] = []any{appendValue}
return
}
if valArr, ok := val.([]any); ok {
valArr = append(valArr, appendValue)
ctx.customData[key] = valArr
}
// 非数组, 忽略追加行为
}
// customDataAppendProperty 向一个map中追加/更新属性
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:11 2025/2/28
func (ctx *Context) customDataAppendProperty(key string, appendKey string, appendValue any) {
ctx.customLock.Lock()
defer ctx.customLock.Unlock()
val, exist := ctx.customData[key]
if !exist || nil == val {
ctx.customData[key] = map[string]any{
appendKey: appendValue,
}
return
}
if valMap, ok := val.(map[string]any); ok {
valMap[appendKey] = appendValue
ctx.customData[key] = valMap
}
// 非map, 忽略追加行为
}
// TraceStart 开始监控
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:24 2025/2/28
func (ctx *Context) TraceStart(action string, actionData map[string]any) int {
return ctx.Trace.StartBehavior(action, actionData)
}
// TraceEnd 完成监控
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:24 2025/2/28
func (ctx *Context) TraceEnd(behaviorID int, endData map[string]any) {
ctx.Trace.FinishBehavior(behaviorID, endData)
}

View File

@ -0,0 +1,46 @@
// Package parse_body ...
//
// Description : parse_body ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-10-22 16:51
package parse_body
import (
"bytes"
"github.com/gin-gonic/gin"
"io"
)
type base struct {
}
// Unmarshal 反序列化方法,可以不指定
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:54 2024/10/22
func (b base) Unmarshal() func(sourceData []byte, receiver any) error {
return nil
}
// DoParse 解析
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:08 2024/10/22
func (b base) DoParse(ctx *gin.Context, receiver any, unmarshalFunc func(sourceData []byte, receiver any) error) ([]byte, error) {
data, err := io.ReadAll(ctx.Request.Body)
if nil != err {
return nil, err
}
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(data))
if nil == unmarshalFunc || nil == receiver {
return data, nil
}
if err := unmarshalFunc(data, receiver); nil != err {
return nil, err
}
return data, err
}

View File

@ -8,12 +8,9 @@
package parse_body
import (
"bytes"
"errors"
"git.zhangdeman.cn/zhangdeman/gin/request/abstract"
"git.zhangdeman.cn/zhangdeman/serialize"
"github.com/gin-gonic/gin"
"io"
"strings"
)
@ -22,12 +19,14 @@ var (
)
func init() {
requestBodyParseAdaptorTable["xml"] = serialize.Xml
requestBodyParseAdaptorTable["ini"] = serialize.Ini
requestBodyParseAdaptorTable["yml"] = serialize.Yml
requestBodyParseAdaptorTable["yaml"] = serialize.Yml
requestBodyParseAdaptorTable["json"] = serialize.JSON
requestBodyParseAdaptorTable["x-www-form-urlencoded"] = serialize.JSON
adaptorList := []abstract.RequestBodyParseAdaptor{
JsonAdaptor{},
FormUrlEncode{},
XmlAdaptor{},
}
for _, itemAdaptor := range adaptorList {
Register(itemAdaptor)
}
}
// Register 注册适配器实例
@ -35,53 +34,27 @@ func init() {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:45 2024/10/22
func Register(requestType string, adaptor abstract.RequestBodyParseAdaptor) {
func Register(adaptor abstract.RequestBodyParseAdaptor) {
if nil == adaptor {
return
}
requestBodyParseAdaptorTable[requestType] = adaptor
requestBodyParseAdaptorTable[adaptor.ContentType()] = adaptor
}
// Execute 解析请求BODY数据
func Execute(ctx *gin.Context, receiver any) ([]byte, error) {
contentType := strings.ToLower(strings.ReplaceAll(ctx.ContentType(), " ", ""))
if len(contentType) == 0 {
return []byte("{}"), nil
}
// 裁剪出真实的类型,之所以截取,是因为 content_type 中可能还包含编码信息, 如 : application/json;chaset=utf8
contentTypeArr := strings.Split(contentType, ";")
contentTypeFormatArr := strings.Split(contentTypeArr[0], "/")
if len(contentTypeFormatArr) != 2 {
return nil, errors.New(contentType + " : content_type format error")
}
// 裁剪出真实的类型,之所以截取,是因为 content_type 中可能还包含编码信息, 如 : application/json;charset=utf8
contentType = contentTypeFormatArr[1]
contentTypeArr := strings.Split(contentType, ";")
contentType = contentTypeArr[0]
if _, exist := requestBodyParseAdaptorTable[contentType]; !exist {
return nil, errors.New(contentType + " : adaptor not found")
}
var (
bodyData []byte
err error
exist bool
body any
)
bodyKey := "_body_read_result"
if body, exist = ctx.Get(bodyKey); exist && nil != body {
bodyData = body.([]byte)
if parseResult, err := requestBodyParseAdaptorTable[contentType].Parse(ctx, receiver); nil != err {
return nil, err
} else {
if bodyData, err = ReadBody(ctx); nil != err {
return nil, err
return parseResult, err
}
// 设置读取结果
ctx.Set(bodyKey, bodyData)
}
if err = requestBodyParseAdaptorTable[contentType].Unmarshal(bodyData, receiver); nil != err {
return nil, err
}
byteData := serialize.JSON.MarshalForByteIgnoreError(receiver)
return byteData, nil
}
// ExecuteForMap 高层级包装表单解析为map
@ -95,34 +68,3 @@ func ExecuteForMap(ctx *gin.Context) (map[string]any, error) {
}
return result, nil
}
// ReadBody 读取请求Body
func ReadBody(ctx *gin.Context) ([]byte, error) {
var (
data []byte
err error
)
// 判断form url encode
if strings.Contains(ctx.ContentType(), "x-www-form-urlencoded") {
if err = ctx.Request.ParseForm(); nil != err {
return nil, err
}
body := map[string]any{}
for paramName, itemParam := range ctx.Request.PostForm {
if len(itemParam) > 0 {
body[paramName] = itemParam[0]
} else {
body[paramName] = ""
}
}
return serialize.JSON.MarshalForByteIgnoreError(body), nil
}
// 读取Body信息
if data, err = io.ReadAll(ctx.Request.Body); nil != err {
return nil, err
}
// 重置Body信息
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(data))
return data, nil
}

View File

@ -0,0 +1,44 @@
// Package parse_body ...
//
// Description : parse_body ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-10-22 16:43
package parse_body
import (
"encoding/json"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/serialize"
"github.com/gin-gonic/gin"
)
type FormUrlEncode struct {
base
}
func (f FormUrlEncode) Parse(ctx *gin.Context, receiver any) ([]byte, error) {
if err := ctx.Request.ParseForm(); nil != err {
return nil, err
}
body := map[string]string{}
for paramName, itemParam := range ctx.Request.PostForm {
if len(itemParam) > 0 {
body[paramName] = itemParam[0]
} else {
body[paramName] = ""
}
}
byteData, _ := json.Marshal(body)
if nil != receiver {
if err := serialize.JSON.UnmarshalWithNumber(byteData, receiver); nil != receiver {
return nil, err
}
}
return byteData, nil
}
func (f FormUrlEncode) ContentType() string {
return consts.MimeTypeXWWWFormUrlencoded
}

View File

@ -0,0 +1,49 @@
// Package parse_body ...
//
// Description : parse_body ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-10-22 16:42
package parse_body
import (
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/serialize"
"github.com/gin-gonic/gin"
)
type JsonAdaptor struct {
base
}
// Parse 解析json请求体
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:13 2024/10/22
func (j JsonAdaptor) Parse(ctx *gin.Context, receiver any) ([]byte, error) {
unmarshalFunc := j.Unmarshal()
if nil == unmarshalFunc {
unmarshalFunc = serialize.JSON.UnmarshalWithNumber
}
return j.DoParse(ctx, receiver, unmarshalFunc)
}
// Unmarshal 指定解析方法
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:56 2024/10/22
func (j JsonAdaptor) Unmarshal() func(sourceData []byte, receiver any) error {
return serialize.JSON.UnmarshalWithNumber
}
// ContentType 请求类型固定返回json
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:59 2024/10/22
func (j JsonAdaptor) ContentType() string {
return consts.MimeTypeJson
}

42
request/parse_body/xml.go Normal file
View File

@ -0,0 +1,42 @@
// Package parse_body ...
//
// Description : parse_body ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-10-22 16:42
package parse_body
import (
"bytes"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/serialize"
"github.com/gin-gonic/gin"
"github.com/sbabiv/xml2map"
)
type XmlAdaptor struct {
base
}
func (x XmlAdaptor) Parse(ctx *gin.Context, receiver any) ([]byte, error) {
unmarshalFunc := x.Unmarshal()
if nil == unmarshalFunc {
unmarshalFunc = serialize.Xml.UnmarshalWithNumber
}
return x.DoParse(ctx, receiver, unmarshalFunc)
}
func (x XmlAdaptor) Unmarshal() func(sourceData []byte, receiver any) error {
return func(sourceData []byte, receiver any) error {
res, err := xml2map.NewDecoder(bytes.NewReader(sourceData)).Decode()
if nil != err {
return err
}
return serialize.JSON.Transition(res, receiver)
}
}
func (x XmlAdaptor) ContentType() string {
return consts.MimeTypeXml
}

View File

@ -0,0 +1,8 @@
// Package parse_body ...
//
// Description : parse_body ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-10-22 16:43
package parse_body

View File

@ -8,15 +8,12 @@
package request
import (
"strings"
"sync"
"git.zhangdeman.cn/zhangdeman/trace"
"git.zhangdeman.cn/zhangdeman/gin/define"
"git.zhangdeman.cn/zhangdeman/gin/request/parse_body"
"git.zhangdeman.cn/zhangdeman/wrapper"
"github.com/gin-gonic/gin"
"strings"
"sync"
)
var (
@ -120,8 +117,8 @@ func (wh *wrapperHandle) GetContentType(ctx *gin.Context, defaultVal string) str
if nil == ctx {
return defaultVal
}
contentType := strings.ToLower(ctx.ContentType())
return wrapper.TernaryOperator.String(len(contentType) > 0, wrapper.String(contentType), wrapper.String(defaultVal)).Value()
contentTypeVal := strings.ToLower(ctx.ContentType())
return wrapper.TernaryOperator.String(len(contentTypeVal) > 0, wrapper.String(contentTypeVal), wrapper.String(defaultVal)).Value()
}
// GetDomain 获取请求Domain
@ -141,8 +138,13 @@ func (wh *wrapperHandle) GetDomain(ctx *gin.Context) string {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:25 2024/7/26
func (wh *wrapperHandle) ParseBody(ctx *gin.Context) (map[string]any, error) {
return parse_body.ExecuteForMap(ctx)
func (wh *wrapperHandle) ParseBody(ctx *gin.Context) map[string]any {
body := map[string]any{}
if _, err := parse_body.Execute(ctx, &body); nil != err {
return map[string]any{}
}
return body
}
// GetResponseBody 获取响应body
@ -269,6 +271,40 @@ func (wh *wrapperHandle) ParseCookie(ctx *gin.Context) map[string]string {
return cookieData
}
// Copy 复制context
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:00 2025/2/28
//
// - ctx *gin.Context 基于哪一个context复制context
// - isCopyContextValue bool : 是否继承父级ctx的自定义value
func (wh *wrapperHandle) Copy(ctx *gin.Context, isCopyContextValue bool, excludeKeyList []string) *gin.Context {
if nil == ctx {
return nil
}
newContext := ctx.Copy()
excludeKeyTable := map[string]bool{}
for _, excludeKey := range excludeKeyList {
excludeKeyTable[excludeKey] = true
}
if isCopyContextValue {
// 上下文设置的业务数据值也继承下来, TODO: 并发读写此处可能panic
for k, v := range newContext.Keys {
if !excludeKeyTable[k] {
// 没有指定不继承
ctx.Set(k, v)
}
}
}
// 设置父级context
ctx.Set("parent_context", ctx)
if nil == ctx.Value("root_context") {
ctx.Set("root_context", ctx)
}
return newContext
}
// GetLogicAfterResponse ...
//
// Author : go_developer@163.com<白茶清欢>
@ -291,12 +327,20 @@ func (wh *wrapperHandle) GetLogicAfterResponse(ctx *gin.Context) *define.LogicAf
return l.(*define.LogicAfterResponse)
}
// GetCustomContext 获取自定义context
func (wh *wrapperHandle) GetCustomContext(ctx *gin.Context) *define.Context {
return define.NewContext(ctx)
}
// GetTraceInstance 获取trace实例
func (wh *wrapperHandle) GetTraceInstance(ctx *gin.Context) *trace.Runtime {
return define.NewContext(ctx).Trace
// GetGinWrapperContext 获取包装之后context
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:41 2025/3/10
func (wh *wrapperHandle) GetGinWrapperContext(ctx *gin.Context) *Context {
if nil == ctx {
return nil
}
if val, exist := ctx.Get(define.GinWrapperContextKey); !exist || nil == val {
newCtx := NewContext(ctx)
newCtx.SetCustom(define.GinWrapperContextKey, newCtx)
return newCtx
} else {
return val.(*Context)
}
}

View File

@ -9,10 +9,7 @@ package response
import (
"fmt"
"git.zhangdeman.cn/zhangdeman/dynamic-struct/wrapper"
"git.zhangdeman.cn/zhangdeman/serialize"
"net/http"
"strings"
"time"
"git.zhangdeman.cn/zhangdeman/exception"
@ -46,7 +43,7 @@ func SetBusinessSuccessCode(code any) {
// Date : 22:37 2022/6/25
func Success(ctx *gin.Context, data any) {
successException := exception.NewSuccess(data)
Send(ctx, successException.Code(), http.StatusOK, successException.Data(), nil)
Send(ctx, successException.GetCode(), successException.GetHttpCode(), successException.GetData(), nil)
}
// SuccessWithExtension 返回扩展数据
@ -54,9 +51,9 @@ func Success(ctx *gin.Context, data any) {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:52 2024/9/24
func SuccessWithExtension(ctx *gin.Context, data any, responseOption *define.ResponseOption) {
func SuccessWithExtension(ctx *gin.Context, data any, extension map[string]any) {
successException := exception.NewSuccess(data)
Send(ctx, successException.Code(), http.StatusOK, successException.Data(), responseOption)
Send(ctx, successException.GetCode(), successException.GetHttpCode(), successException.GetData(), extension)
}
// Send 基础的发送数据
@ -64,69 +61,32 @@ func SuccessWithExtension(ctx *gin.Context, data any, responseOption *define.Res
// Author : go_developer@163.com<白茶清欢>
//
// Date : 22:40 2022/6/25
func Send(ctx *gin.Context, code any, httpCode int, data any, responseOption *define.ResponseOption) {
if nil == responseOption {
responseOption = &define.ResponseOption{
ContentType: "application/json; charset=utf-8",
Extension: make(map[string]any),
}
}
if len(responseOption.ContentType) == 0 {
responseOption.ContentType = "application/json; charset=utf-8"
}
if len(responseOption.XmlName) == 0 {
responseOption.XmlName = "ResponseData"
}
func Send(ctx *gin.Context, code any, httpCode int, data any, extension map[string]any) {
// 设置请求是否成功的标识
ctx.Set(define.GetHttpHandleConfig().RequestIsSuccessField, fmt.Sprintf("%v", code) == fmt.Sprintf("%v", successBusinessCode))
if ctx.GetBool(hasSendResponseFlag) {
// 已经发送过数据, 后面在发送数据, 不执行
return
}
finishRequestTime := time.Now().UnixMilli()
// 设置数据已发送的标识
defer ctx.Set(hasSendResponseFlag, true)
finishRequestTime := time.Now()
responseData := BuildResponseData(ctx, finishRequestTime, code, data, responseOption.Extension)
// 记录完成时间
responseConfig := define.GetHttpHandleConfig()
ctx.Set(responseConfig.FinishRequestTimeField, finishRequestTime.UnixMilli())
ctx.Set(responseConfig.ResponseDataField, responseData)
responseException := exception.New(code, responseData)
responseContentType := getResponseDataType(responseOption.ContentType)
responseStr := serialize.JSON.MarshalForStringIgnoreError(responseException.Data())
if responseInstance, err := wrapper.NewJson(responseStr, &wrapper.Option{XmlName: responseOption.XmlName}); nil != err {
// 接口处理成功, 数据序列化出现异常
panic(err.Error()) // 直接panic, 交给gin处理
} else {
finalResponseData, _ := responseInstance.Marshal(responseContentType)
ctx.Data(http.StatusOK, responseOption.ContentType, finalResponseData)
}
}
// getResponseDataType 获取相应数据类型
func getResponseDataType(contentType string) string {
if contentType == "" {
return "json"
}
applicationInfo := strings.Split(contentType, ";")[0]
applicationInfoArr := strings.Split(applicationInfo, "/")
return applicationInfoArr[len(applicationInfoArr)-1]
}
// BuildResponseData 构建响应数据
func BuildResponseData(ctx *gin.Context, finishTime time.Time, code any, data any, extension map[string]any) map[string]any {
responseConfig := define.GetHttpHandleConfig()
responseData := map[string]any{
responseConfig.ResponseCodeField: code,
responseConfig.ResponseMessageField: exception.GetMessage(code),
responseConfig.ResponseTraceIDField: ctx.GetString(responseConfig.ResponseTraceIDField),
responseConfig.ResponseDataField: data,
responseConfig.HandleRequestCostField: finishTime.UnixMilli() - ctx.GetInt64(responseConfig.StartRequestTimeField),
responseConfig.HandleRequestCostField: finishRequestTime - ctx.GetInt64(responseConfig.StartRequestTimeField),
}
if responseConfig.EnableExtensionOutput && nil != extension {
responseData[responseConfig.ExtensionOutputField] = extension
}
return responseData
// 记录完成时间
ctx.Set(responseConfig.FinishRequestTimeField, finishRequestTime)
ctx.Set(responseConfig.ResponseDataField, responseData)
responseException := exception.New(code, httpCode, responseData)
ctx.JSON(responseException.GetHttpCode(), responseException.GetData())
}
// SendWithStatusOK ...
@ -143,9 +103,9 @@ func SendWithStatusOK(ctx *gin.Context, code any, data any) {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 13:08 2022/6/26
func SendWithException(ctx *gin.Context, e exception.IException, responseOption *define.ResponseOption) {
func SendWithException(ctx *gin.Context, e exception.IException, data map[string]any) {
if nil == e {
e = exception.NewSuccess(map[string]any{})
e = exception.NewSuccess(data)
}
if !define.GetHttpHandleConfig().DisableDebugStackOutput && nil != e {
stack := e.GetStack()
@ -153,7 +113,11 @@ func SendWithException(ctx *gin.Context, e exception.IException, responseOption
fmt.Println(stack)
}
}
Send(ctx, e.Code(), http.StatusOK, e.Data(), responseOption)
outputData := map[string]any{
"e_data": e.GetData(),
"u_e_data": data,
}
Send(ctx, e.GetCode(), e.GetHttpCode(), outputData, nil)
}
// JSON ctx.JSON 的平替, 增加了数据是否已相应的标识

View File

@ -69,9 +69,9 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
needRegister = false
return
}
// 第一个参数必须是 *gin.Context 或者 *define.Context
paramOne := methodType.In(1).String()
if paramOne != GinContextType && paramOne != CustomContextType {
// 第一个参数必须是 *gin.Context
firstParamStr := methodType.In(1).String()
if firstParamStr != GinContextType && firstParamStr != GinWrapperContextType {
needRegister = false
return
}
@ -106,8 +106,9 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
return
}
}
// 是否gin包装后的context
cfg.IsGinWrapperContext = firstParamStr == GinWrapperContextType
// 解析meta信息
cfg.CtxType = paramOne
cfg.Path = metaField.Tag.Get(TagNamePath)
cfg.RequestMethod = metaField.Tag.Get(TagNameMethod)
cfg.Desc = metaField.Tag.Get(TagNameDesc)

View File

@ -15,7 +15,7 @@ const (
PrefixFuncName = "RouterPrefix" // 路由前缀函数名称
MiddlewareFuncName = "RouterMiddleware" // 路由中间件函数名称
GinContextType = "*gin.Context" // gin context 类型名称
CustomContextType = "*define.Context" // custom context 类型名称
GinWrapperContextType = "*request.Context" // gin context 类型名称
ErrorType = "error" // error类型
ErrorInterfaceFuncName = "Error" // error接口需要实现的方法名称
)
@ -42,11 +42,11 @@ type UriConfig struct {
TagList []string `json:"tag_list"` // 接口分组
Desc string `json:"desc"` // 接口描述
OutputStrict bool `json:"output_strict"` // 接口是否为严格模式 : 不配置,可返回任意类型, 配置, 必须返回结构体或者map
CtxType string `json:"ctx_type"` // ctx参数类型
FormDataType reflect.Type `json:"-"` // 表单数据类型
ResultDataType reflect.Type `json:"-"` // 返回值数据类型
ApiStructValue reflect.Value `json:"-"` // 逻辑函数所属结构体取值
ApiLogicFunc reflect.Method `json:"-"` // 自定义的接口逻辑
IsGinWrapperContext bool `json:"is_gin_wrapper_context"` // 是否gin包装后的context
}
// UriParam 接口参数配置

View File

@ -8,15 +8,13 @@
package router
import (
"errors"
"reflect"
"sync"
"git.zhangdeman.cn/zhangdeman/exception"
"git.zhangdeman.cn/zhangdeman/gin/define"
"git.zhangdeman.cn/zhangdeman/gin/request"
"git.zhangdeman.cn/zhangdeman/gin/response"
"github.com/gin-gonic/gin"
"reflect"
"sync"
)
// RequestHandler 获取请求处理方法
@ -44,9 +42,7 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
// 格式化验证错误的信息
err = GetValidateErr(formValue, err)
e = exception.NewFromError(400, err)
response.SendWithException(ctx, e, &define.ResponseOption{
ContentType: "application/json;charset=utf-8",
})
response.SendWithException(ctx, e, nil)
ctx.Abort()
return
}
@ -62,12 +58,7 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
ctx.Set(define.LogicAfterResponseKey, logicAfterResponse)
defer func() {
go func() {
// 执行响应之后的相关逻辑
defer func() {
if r := recover(); r != nil {
}
}()
defer recover()
if isSuccess {
for _, itemFunc := range logicAfterResponse.SuccessHookFuncList {
if nil != itemFunc {
@ -88,22 +79,22 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
if uriCfg.FormDataType.Kind() != reflect.Ptr {
inputValue = inputValue.Elem()
}
var firstParam reflect.Value
if uriCfg.CtxType == CustomContextType {
customCtx := ctx.MustGet(define.CustomContextKey)
firstParam = reflect.ValueOf(customCtx)
} else {
firstParam = reflect.ValueOf(ctx)
ginWrapperContext := request.NewContext(ctx)
// wrapper context 设置到 gin context
ginWrapperContext.Set(define.GinWrapperContextKey, ginWrapperContext)
ctxReflect := reflect.ValueOf(ctx)
if uriCfg.IsGinWrapperContext {
ctxReflect = reflect.ValueOf(ginWrapperContext)
}
resList := uriCfg.ApiLogicFunc.Func.Call([]reflect.Value{uriCfg.ApiStructValue, firstParam, inputValue})
resList := uriCfg.ApiLogicFunc.Func.Call([]reflect.Value{uriCfg.ApiStructValue, ctxReflect, inputValue})
if resList[1].IsNil() {
// 请求成功
isSuccess = true
response.SuccessWithExtension(ctx, resList[0].Interface(), &define.ResponseOption{ContentType: "application/json;charset=utf-8"})
response.Success(ctx, resList[0].Interface())
return
}
// 请求失败
if ok = errors.As(resList[1].Interface().(error), &e); ok {
if e, ok = resList[1].Interface().(exception.IException); ok {
// 本身就是exception.IException
} else if err, ok = resList[1].Interface().(error); ok {
e = exception.NewFromError(-1, err)
@ -112,9 +103,7 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
"err": resList[1].Interface(),
})
}
response.SendWithException(ctx, e, &define.ResponseOption{
ContentType: "application/json;charset=utf-8",
})
response.SendWithException(ctx, e, nil)
return
}
}

View File

@ -8,11 +8,10 @@
package router
import (
"strings"
apiDocDefine "git.zhangdeman.cn/gateway/api-doc/define"
"git.zhangdeman.cn/zhangdeman/gin/middleware"
"github.com/gin-gonic/gin"
"strings"
)
type SetServerOptionFunc func(so *serverOption)
@ -30,6 +29,7 @@ type serverOption struct {
serverInfo *apiDocDefine.Info // 服务器信息
serverList []*apiDocDefine.ServerItem // 服务器环境列表
enablePprof bool // 启用pprof
enableRequestInit bool // 初始化请求,生成trace_id 设置请求时间等
enableCors bool // 启动跨域支持
loggerCfg *middleware.AccessConfig // 日志配置
}
@ -126,6 +126,17 @@ func WithPprofEnable() SetServerOptionFunc {
}
}
// WithEnableRequestInit 全局配置初始化
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:56 2025/2/22
func WithEnableRequestInit() SetServerOptionFunc {
return func(so *serverOption) {
so.enableRequestInit = true
}
}
// WithEnableCors 启用全局跨域
//
// Author : go_developer@163.com<白茶清欢>

214
router/register.go Normal file
View File

@ -0,0 +1,214 @@
// Package router ...
//
// Description : router ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-07-20 21:39
package router
import (
"fmt"
"git.zhangdeman.cn/zhangdeman/exception"
"git.zhangdeman.cn/zhangdeman/gin/middleware"
"git.zhangdeman.cn/zhangdeman/gin/request"
"git.zhangdeman.cn/zhangdeman/gin/response"
"git.zhangdeman.cn/zhangdeman/wrapper"
"github.com/gin-gonic/gin"
"net/http"
"reflect"
"strings"
)
var (
Debug = false // 是否开启DEBUG
ginRouter = gin.Default()
)
func init() {
}
// Register 注册路由
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:40 2024/7/20
func Register(port int, controllerList ...any) error {
for _, itemController := range controllerList {
if nil == itemController {
// 忽略空指针
continue
}
parseController(itemController)
}
return ginRouter.Run(fmt.Sprintf(":%d", port))
}
// parseController 解析controller
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 22:10 2024/7/20
func parseController(controller any) {
controllerType := reflect.TypeOf(controller)
controllerValue := reflect.ValueOf(controller)
routerPrefix := "/"
// 解析路由前缀函数
// routerPrefix 不能有任何入参, 并且只能有一个返回值,
// 返回值类型为字符串, 为具体路由前缀
routerPrefixFunc, routerPrefixFuncExist := controllerType.MethodByName(PrefixFuncName)
if routerPrefixFuncExist {
routerPrefixFuncType := routerPrefixFunc.Type
if routerPrefixFuncType.NumIn() == 1 && // 无任何入参, 正在没有如何入参情况下, 第一个参数是结构体指针
routerPrefixFuncType.NumOut() == 1 && // 只能有一个返回值
routerPrefixFuncType.Out(0).Kind() == reflect.String { // 返回值必须是字符串
routerPrefix = routerPrefixFunc.Func.Call([]reflect.Value{controllerValue})[0].String()
}
}
// 请求组的中间件
middlewareList := make([]gin.HandlerFunc, 0)
routerMiddlewareFunc, routerMiddlewareFuncExist := controllerType.MethodByName(MiddlewareFuncName)
if routerMiddlewareFuncExist {
routerMiddlewareFuncType := routerMiddlewareFunc.Type
if routerMiddlewareFuncType.NumIn() == 1 && // 无需任何参数
routerMiddlewareFuncType.NumOut() == 1 && // 只能有一个返回值
routerMiddlewareFuncType.Out(0).String() == "[]gin.HandlerFunc" { // 返回值必须是gin.HandlerFunc
res := routerMiddlewareFunc.Func.Call([]reflect.Value{controllerValue})
if !res[0].IsNil() {
middlewareList = res[0].Interface().([]gin.HandlerFunc)
}
}
}
for funcIdx := 0; funcIdx < controllerType.NumMethod(); funcIdx++ {
method := controllerType.Method(funcIdx)
if method.Name == PrefixFuncName || method.Name == MiddlewareFuncName {
continue
}
methodType := method.Type
uriConfig, err := parseUriConfig(methodType, routerPrefix)
if nil != err {
debugLog("parseUriConfig error : %s -> %s", err.Error(), methodType.Kind().String())
}
if nil == uriConfig {
continue
}
registerUri(uriConfig, controllerValue.Method(funcIdx), middlewareList)
}
}
// parseUriConfig 解析Uri配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:40 2024/7/21
func parseUriConfig(methodType reflect.Type, routerPrefix string) (*UriConfig, error) {
if methodType.NumIn() != 3 || // 结构体指针 + 两个参数
methodType.NumOut() != 2 { // 两个返回值
return nil, nil
}
// 接口logic共计两个参数. 两个返回值, 格式 : func(ctx *gin.Context, formData any[组合Meta]) (any[response], error)
// 解析第一个参数是 *gin.Context / 或者包装后的 request.Context
firstParamStr := methodType.In(1).String()
if firstParamStr != "*gin.Context" && firstParamStr != "*request.Context" {
return nil, nil
}
// 解析第二个参数是组合Meta的form表单
formType := methodType.In(2)
if formType.Kind() == reflect.Ptr {
formType = methodType.In(2).Elem()
}
metaField, metaFieldExist := formType.FieldByName(FieldNameMeta)
if !metaFieldExist {
return nil, nil
}
uriConfig := &UriConfig{
Path: strings.TrimRight(routerPrefix, "/") + "/" + strings.TrimLeft(metaField.Tag.Get(TagNamePath), "/"),
RequestMethod: strings.ToUpper(metaField.Tag.Get(TagNameMethod)),
TagList: strings.Split(metaField.Tag.Get(TagNameUriTag), "|"),
Desc: metaField.Tag.Get(TagNameDesc),
OutputStrict: wrapper.ArrayType([]string{"", "true"}).Has(strings.ToLower(metaField.Tag.Get(TagNameOutputStrict))) >= 0,
FormDataType: methodType.In(2).Elem(),
}
// 校验 FormDataType
for fieldIdx := 0; fieldIdx < uriConfig.FormDataType.NumField(); fieldIdx++ {
if uriConfig.FormDataType.Field(fieldIdx).Type.Kind() == reflect.Interface {
panic("request param set type `interface` is not allowed")
}
}
return uriConfig, nil
}
// registerUri 注册路由
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:00 2024/7/21
func registerUri(uriConfig *UriConfig, methodValue reflect.Value, middlewareList []gin.HandlerFunc) {
if nil == middlewareList {
middlewareList = make([]gin.HandlerFunc, 0)
}
handlerFunc := func(ctx *gin.Context) {
formDataReceiver := reflect.New(uriConfig.FormDataType)
if err := request.Form.Parse(ctx, formDataReceiver.Interface()); nil != err {
panic(err)
}
returnValue := methodValue.Call([]reflect.Value{reflect.ValueOf(ctx), formDataReceiver})
businessData := returnValue[0].Interface()
errData := returnValue[1]
if errData.IsNil() {
response.Success(ctx, businessData)
return
}
err := errData.Interface()
if e, ok := err.(exception.IException); ok {
response.SendWithException(ctx, e, map[string]any{"business_data": businessData})
return
} else {
response.SendWithException(ctx, exception.NewFromError(-1, errData.Interface().(error)), map[string]any{"business_data": businessData})
return
}
}
middlewareList = append(middlewareList, handlerFunc)
middlewareList = append([]gin.HandlerFunc{
middleware.InitRequest(),
}, middlewareList...)
switch uriConfig.RequestMethod {
case http.MethodGet:
ginRouter.GET(uriConfig.Path, middlewareList...)
case http.MethodHead:
ginRouter.HEAD(uriConfig.Path, middlewareList...)
case http.MethodPost:
ginRouter.PUT(uriConfig.Path, middlewareList...)
case http.MethodPut:
ginRouter.PUT(uriConfig.Path, middlewareList...)
case http.MethodPatch:
ginRouter.PATCH(uriConfig.Path, middlewareList...)
case http.MethodDelete:
ginRouter.DELETE(uriConfig.Path, middlewareList...)
case http.MethodConnect:
ginRouter.Handle(http.MethodConnect, uriConfig.Path, middlewareList...)
case http.MethodOptions:
ginRouter.OPTIONS(uriConfig.Path, middlewareList...)
case http.MethodTrace:
ginRouter.Handle(http.MethodTrace, uriConfig.Path, middlewareList...)
case "ANY":
ginRouter.Any(uriConfig.Path, middlewareList...)
default:
panic(uriConfig.Path + " : " + uriConfig.RequestMethod + " is not support")
}
}
// debugLog ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:32 2024/7/21
func debugLog(format string, valList ...any) {
if !Debug {
return
}
fmt.Printf("[DEBUG] "+format+"\n", valList...)
}

47
router/register_test.go Normal file
View File

@ -0,0 +1,47 @@
// Package router ...
//
// Description : router ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-07-20 23:24
package router
import (
"git.zhangdeman.cn/zhangdeman/gin/request"
"testing"
)
type TestController struct{}
func (t TestController) Logic(ctx *request.Context, formData *TestForm) (TestOut, error) {
return TestOut{
FormData: formData,
}, nil
}
type TestOut struct {
Age int `json:"age" form:"age" binding:"min=20" err_msg:"年龄不能小于20"`
Name string `json:"name" form:"name"`
Test *Test `json:"test" form:"test"`
Num *int64 `json:"num" form:"num"`
FormData *TestForm `json:"form_data" form:"form_data"`
}
type TestForm struct {
Meta `tag:"测试表单" path:"/a/b/c/d" desc:"测试接口" method:"GET"`
Age int `json:"age" form:"age" binding:"min=20" err_msg:"年龄不能小于20"`
Name string `json:"name" form:"name"`
Test *Test `json:"test" form:"test"`
Num *int64 `json:"num" form:"num"`
}
type Test struct {
L string `json:"l"`
}
func Test_parseController(t *testing.T) {
SetValidateErrTag("err_msg")
s := NewServer(8888, nil)
s.Group("test", nil, TestController{})
s.Start()
}

View File

@ -9,17 +9,13 @@ package router
import (
"fmt"
"git.zhangdeman.cn/zhangdeman/graceful"
"net/http"
"strings"
"git.zhangdeman.cn/zhangdeman/gin/define"
apiDoc "git.zhangdeman.cn/gateway/api-doc"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/gin/middleware"
"git.zhangdeman.cn/zhangdeman/gin/middleware/request_cors"
"github.com/gin-contrib/pprof"
"net/http"
"strings"
apiDocDefine "git.zhangdeman.cn/gateway/api-doc/define"
"github.com/gin-gonic/gin"
@ -74,14 +70,10 @@ func NewServer(port int, optionList ...SetServerOptionFunc) *server {
}
option := newServerOption(port, optionList...)
globalMiddlewareList := make([]gin.HandlerFunc, 0)
// CustomContext 必须在第一个, 并且进行初始化
globalMiddlewareList = append(
globalMiddlewareList,
func(ctx *gin.Context) {
// 初始化上下文以及基础信息
_ = define.NewContext(ctx)
},
)
if option.enableRequestInit {
// 初始化请求中间件
globalMiddlewareList = append(globalMiddlewareList, middleware.InitRequest())
}
if nil != option.loggerCfg {
// 请求日志记录中间件
globalMiddlewareList = append(globalMiddlewareList, middleware.LogRequest(option.loggerCfg))
@ -139,12 +131,7 @@ type server struct {
func (s *server) Start() {
// 注册文档
s.uiInstance.RegisterHandler(s.router, s.option.swaggerBaseUri)
gracefulServer := graceful.NewServer(fmt.Sprintf(":%d", s.port), s.Router())
if err := gracefulServer.ListenAndServe(); err != nil {
if strings.Contains(err.Error(), "use of closed network connection") {
fmt.Println("接收到退出指令, 服务平滑关闭")
return
}
if err := s.router.Run(fmt.Sprintf(":%d", s.port)); err != nil {
panic("服务启动监听失败" + err.Error())
}
}

View File

@ -1,19 +0,0 @@
// Package router ...
//
// Description : router ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-05-28 20:58
package router
import (
"github.com/gin-gonic/gin"
"testing"
)
func TestNewServer(t *testing.T) {
s := NewServer(9087)
s.Router().GET("/ping", func(c *gin.Context) {})
s.Start()
}