feat: 修复golint相关警告信息

This commit is contained in:
2025-12-26 12:01:52 +08:00
parent c23d938092
commit 1636a2652f
9 changed files with 21 additions and 25 deletions

View File

@@ -81,8 +81,6 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
return
}
cfg.ResultDataType = methodType.Out(0)
if cfg.ResultDataType == nil {
}
if methodType.Out(1).Kind().String() != ErrorType {
// 判断是否是实现 error接口的方法
outputErrParse := false
@@ -106,7 +104,6 @@ func (c controller) methodConfig(reflectMethod reflect.Method) (cfg UriConfig, n
// 开启输出严格模式校验
if methodType.Out(0).Kind() != reflect.Struct && methodType.Out(0).Kind() != reflect.Map {
panic(cfg.Path + " : 接口配置输出严格校验, 输出数据类型必须为 struct 或 *struct 或 map, 实际返回数据类型 : " + methodType.Out(0).Kind().String())
return
}
}

View File

@@ -115,6 +115,5 @@ func (s *server) RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
response.SendWithException(ctx, e, &define.ResponseOption{
ContentType: consts.MimeTypeJson,
})
return
}
}

View File

@@ -18,19 +18,23 @@ import (
// hook 执行hook逻辑
func (s *server) hook(ctx *gin.Context, uriCfg UriConfig) {
responseAfter, exist := ctx.Get(consts.GinLogicAfterResponseKey)
var (
exists bool
isSuccess any
responseAfter any
)
innerContext := util.GinCtxToContext(ctx)
if !exist || nil != responseAfter {
if responseAfter, exists = ctx.Get(consts.GinLogicAfterResponseKey); !exists || nil != responseAfter {
// 未配置
logger.Instance.Debug("未配置Logic执行后的hook逻辑", pkgLogger.NewLogData(innerContext, logger.RecordType, logger.CodeLogicHook, map[string]any{
logger.Instance.Debug("未配置 Logic 执行后的 hook 逻辑", pkgLogger.NewLogData(innerContext, logger.RecordType, logger.CodeLogicHook, map[string]any{
"uri": uriCfg.Path,
"logic_after_response_key": consts.GinLogicAfterResponseKey,
}).ToFieldList()...)
return
}
isSuccess, exist := ctx.Get(consts.GinRequestSuccess)
success := false
if nil != isSuccess && (isSuccess == "1" || isSuccess == "true" || isSuccess.(bool)) {
if isSuccess, exists = ctx.Get(consts.GinRequestSuccess); exists && nil != isSuccess && (isSuccess == "1" || isSuccess == "true" || isSuccess.(bool)) {
success = true
}
hookInstance := responseAfter.(*define.LogicAfterResponse)
@@ -47,14 +51,12 @@ func (s *server) hookAfter(ctx *gin.Context, uriCfg UriConfig, hookInstance *def
innerContext := util.GinCtxToContext(ctx)
defer func() {
if err := recover(); err != nil {
logger.Instance.Error("hook执行异常", pkgLogger.NewLogData(innerContext, logger.RecordType, logger.CodeLogicHook, map[string]any{
logger.Instance.Error("hook 执行异常", pkgLogger.NewLogData(innerContext, logger.RecordType, logger.CodeLogicHook, map[string]any{
"uri": uriCfg.Path,
"logic_after_response_key": consts.GinLogicAfterResponseKey,
"error": err.(error).Error(),
"logic_success": success,
}).ToFieldList()...)
} else {
}
}()
if success {

View File

@@ -77,10 +77,6 @@ func NewServer(port int, optionList ...SetServerOptionFunc) *server {
if !option.disableInitRequest { // 启用了初始化请求
globalMiddlewareList = append(globalMiddlewareList, middleware.InitRequest()) // 初始化请求
}
// CustomContext 必须在第一个, 并且进行初始化
globalMiddlewareList = append(
globalMiddlewareList,
)
if nil != option.loggerCfg {
// 请求日志记录中间件
globalMiddlewareList = append(globalMiddlewareList, middleware.LogRequest(option.loggerCfg))