Compare commits
3 Commits
d4052bcc4f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 146d9df639 | |||
| 9143bf84f8 | |||
| 655a4f5021 |
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ toolchain go1.24.2
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/api-doc v1.0.3-0.20251013152001-868ee8955623
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20251101052451-27b111113aa3
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20251101092813-3dd9fb807f1c
|
||||
git.zhangdeman.cn/zhangdeman/dynamic-struct v0.0.0-20251013092857-dcf591d4e8a8
|
||||
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab
|
||||
git.zhangdeman.cn/zhangdeman/graceful v0.0.0-20250529070945-92833db6f3a4
|
||||
|
||||
4
go.sum
4
go.sum
@ -1,9 +1,9 @@
|
||||
git.zhangdeman.cn/zhangdeman/api-doc v1.0.3-0.20251013152001-868ee8955623 h1:QiqETEQx2PBv2fF3UwPS11dsbVDcF3WNCmRRA8zrqAk=
|
||||
git.zhangdeman.cn/zhangdeman/api-doc v1.0.3-0.20251013152001-868ee8955623/go.mod h1:ryyMI2gPgotFD1lZC50p2vRyX8bf3MRwO9tos41z4WU=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250916024308-d378e6c57772 h1:Yo1ur3LnDF5s7F7tpJsNrdUSF8LwYKnN9TdQU32F3eU=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250916024308-d378e6c57772/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20251101052451-27b111113aa3 h1:MQJCu5ZIDUYJSQ7rGZni4gsxgGmpXgWgNBHJzHSOvxw=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20251101052451-27b111113aa3/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20251101092813-3dd9fb807f1c h1:H0Tlh7i5UtCLwwhPFEqIO7V+vydQ7YgMtPQI7iCxiSI=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20251101092813-3dd9fb807f1c/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
|
||||
git.zhangdeman.cn/zhangdeman/dynamic-struct v0.0.0-20251013092857-dcf591d4e8a8 h1:Pw981jG3hH9ZHrB3s1xPpsZafgX3USuMAjnGi2GEP9Y=
|
||||
git.zhangdeman.cn/zhangdeman/dynamic-struct v0.0.0-20251013092857-dcf591d4e8a8/go.mod h1:xtCw3om5DRrG30EfQd/lfQPXgptfK7l9oBSt4Kdhjok=
|
||||
git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda h1:bMD6r9gjRy7cO+T4zRQVYAesgIblBdTnhzT1vN5wjvI=
|
||||
|
||||
@ -11,11 +11,11 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/trace"
|
||||
"git.zhangdeman.cn/zhangdeman/wrapper/op_ternary"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"git.zhangdeman.cn/zhangdeman/gin/define"
|
||||
"git.zhangdeman.cn/zhangdeman/gin/request/parse_body"
|
||||
"git.zhangdeman.cn/zhangdeman/trace"
|
||||
"git.zhangdeman.cn/zhangdeman/wrapper/op_ternary"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -242,33 +242,29 @@ func (wh *wrapperHandle) ParseCookie(ctx *gin.Context) map[string]string {
|
||||
}
|
||||
|
||||
// GetLogicAfterResponse ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:54 2025/2/28
|
||||
func (wh *wrapperHandle) GetLogicAfterResponse(ctx *gin.Context) *define.LogicAfterResponse {
|
||||
if nil == ctx || nil == ctx.Request {
|
||||
return nil
|
||||
}
|
||||
l, exist := ctx.Get(define.LogicAfterResponseKey)
|
||||
l, exist := ctx.Get(consts.GinLogicAfterResponseKey)
|
||||
if !exist || nil == l {
|
||||
l = &define.LogicAfterResponse{
|
||||
SuccessHookFuncList: make([]func(), 0),
|
||||
FailureHookFuncList: make([]func(), 0),
|
||||
SuccessHookFuncList: make([]func(ctx *gin.Context), 0),
|
||||
FailureHookFuncList: make([]func(ctx *gin.Context), 0),
|
||||
Lock: &sync.RWMutex{},
|
||||
}
|
||||
ctx.Set(define.LogicAfterResponseKey, l)
|
||||
ctx.Set(consts.GinLogicAfterResponseKey, l)
|
||||
}
|
||||
// 就这么写, key值如果被其他人覆盖成非法值, 此处会直接panic
|
||||
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
|
||||
i, exist := ctx.Get(consts.GinTraceInstanceField)
|
||||
if !exist || nil == i {
|
||||
i = trace.NewRuntime(wh.GetCtxStringData(ctx, consts.GinTraceIDField, ""), 2)
|
||||
ctx.Set(consts.GinTraceInstanceField, i)
|
||||
}
|
||||
return i.(*trace.Runtime)
|
||||
}
|
||||
|
||||
@ -82,8 +82,8 @@ func (s *server) RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
|
||||
ctx.Set(consts.GinRequestSuccess, false)
|
||||
// 初始化响应之后logic
|
||||
logicAfterResponse := &define.LogicAfterResponse{
|
||||
SuccessHookFuncList: make([]func(), 0),
|
||||
FailureHookFuncList: make([]func(), 0),
|
||||
SuccessHookFuncList: make([]func(ctx *gin.Context), 0),
|
||||
FailureHookFuncList: make([]func(ctx *gin.Context), 0),
|
||||
Lock: &sync.RWMutex{},
|
||||
}
|
||||
// 此处暴露出去,是为了使用方可以获取到对应数据
|
||||
|
||||
@ -15,8 +15,6 @@ import (
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/graceful"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/gin/define"
|
||||
|
||||
apiDoc "git.zhangdeman.cn/zhangdeman/api-doc"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"git.zhangdeman.cn/zhangdeman/gin/middleware"
|
||||
@ -67,10 +65,6 @@ func newServerOption(port int, optionList ...SetServerOptionFunc) *serverOption
|
||||
}
|
||||
|
||||
// NewServer server实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:20 2025/2/7
|
||||
func NewServer(port int, optionList ...SetServerOptionFunc) *server {
|
||||
if port < 80 {
|
||||
panic("port should be greater than 80")
|
||||
@ -86,10 +80,6 @@ func NewServer(port int, optionList ...SetServerOptionFunc) *server {
|
||||
// CustomContext 必须在第一个, 并且进行初始化
|
||||
globalMiddlewareList = append(
|
||||
globalMiddlewareList,
|
||||
func(ctx *gin.Context) {
|
||||
// 初始化上下文以及基础信息
|
||||
_ = define.NewContext(ctx)
|
||||
},
|
||||
)
|
||||
if nil != option.loggerCfg {
|
||||
// 请求日志记录中间件
|
||||
|
||||
Reference in New Issue
Block a user