(ginCtx *gin.Context)
| 47 | } |
| 48 | |
| 49 | func (o *openapiCheck) Handler(ginCtx *gin.Context) { |
| 50 | notIgnore := !ignore.IsIgnorePath("openapi", ginCtx.Request.Method, ginCtx.FullPath()) |
| 51 | if !notIgnore { |
| 52 | return |
| 53 | } |
| 54 | authorization := ginCtx.GetHeader("Authorization") |
| 55 | if authorization == "" { |
| 56 | apikey, has := ginCtx.GetQuery("apikey") |
| 57 | if !has { |
| 58 | ginCtx.AbortWithStatusJSON(403, gin.H{"code": -8, "msg": "invalid token", "success": "fail"}) |
| 59 | return |
| 60 | } |
| 61 | authorization = apikey |
| 62 | } |
| 63 | authorization = strings.TrimPrefix(authorization, "Bearer ") |
| 64 | if authorization == o.apikey { |
| 65 | return |
| 66 | } |
| 67 | list, err := o.apikeyModule.SimpleList(ginCtx) |
| 68 | if err != nil { |
| 69 | ginCtx.AbortWithStatusJSON(403, gin.H{"code": -8, "msg": "invalid token", "success": "fail"}) |
| 70 | return |
| 71 | } |
| 72 | if len(list) == 0 { |
| 73 | ginCtx.AbortWithStatusJSON(403, gin.H{"code": -8, "msg": "invalid token", "success": "fail"}) |
| 74 | return |
| 75 | } |
| 76 | for _, item := range list { |
| 77 | if item.Value == authorization { |
| 78 | if item.Expired != 0 && item.Expired < time.Now().Unix() { |
| 79 | continue |
| 80 | } |
| 81 | return |
| 82 | } |
| 83 | } |
| 84 | ginCtx.AbortWithStatusJSON(403, gin.H{"code": -8, "msg": "invalid token", "success": "fail"}) |
| 85 | } |
nothing calls this directly
no test coverage detected