feat: 修复golint相关警告信息
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user