增加CustomContext

This commit is contained in:
2025-04-12 21:01:59 +08:00
parent 53ecd0c267
commit 91a1d34474
11 changed files with 138 additions and 278 deletions

View File

@ -8,13 +8,15 @@
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 获取请求处理方法
@ -58,7 +60,12 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
ctx.Set(define.LogicAfterResponseKey, logicAfterResponse)
defer func() {
go func() {
defer recover()
// 执行响应之后的相关逻辑
defer func() {
if r := recover(); r != nil {
}
}()
if isSuccess {
for _, itemFunc := range logicAfterResponse.SuccessHookFuncList {
if nil != itemFunc {
@ -87,7 +94,7 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
return
}
// 请求失败
if e, ok = resList[1].Interface().(exception.IException); ok {
if ok = errors.As(resList[1].Interface().(error), &e); ok {
// 本身就是exception.IException
} else if err, ok = resList[1].Interface().(error); ok {
e = exception.NewFromError(-1, err)