接口入口函数首个参数支持custom context

This commit is contained in:
2025-04-12 21:52:07 +08:00
parent a7fed88714
commit e0d5e9c94b
4 changed files with 15 additions and 5 deletions

View File

@ -86,7 +86,13 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
if uriCfg.FormDataType.Kind() != reflect.Ptr {
inputValue = inputValue.Elem()
}
resList := uriCfg.ApiLogicFunc.Func.Call([]reflect.Value{uriCfg.ApiStructValue, reflect.ValueOf(ctx), inputValue})
var firstParam reflect.Value
if uriCfg.CtxType == define.CustomContextKey {
firstParam = reflect.ValueOf(ctx.MustGet(define.CustomContextKey))
} else {
firstParam = reflect.ValueOf(ctx)
}
resList := uriCfg.ApiLogicFunc.Func.Call([]reflect.Value{uriCfg.ApiStructValue, firstParam, inputValue})
if resList[1].IsNil() {
// 请求成功
isSuccess = true