GetEnableShortID get short id flag from context
(ctx context.Context)
| 28 | |
| 29 | // GetEnableShortID get short id flag from context |
| 30 | func GetEnableShortID(ctx context.Context) bool { |
| 31 | // Check gin context first (set by ShortIDMiddleware via ctx.Set) |
| 32 | if ginCtx, ok := ctx.(*gin.Context); ok { |
| 33 | flag, ok := ginCtx.Get(constant.ShortIDFlag) |
| 34 | if ok { |
| 35 | if flag, ok := flag.(bool); ok { |
| 36 | return flag |
| 37 | } |
| 38 | return false |
| 39 | } |
| 40 | } |
| 41 | // Fallback for non-gin contexts (e.g., SitemapCron uses context.WithValue) |
| 42 | flag, ok := ctx.Value(constant.ShortIDContextKey).(bool) |
| 43 | if ok { |
| 44 | return flag |
| 45 | } |
| 46 | return false |
| 47 | } |
no test coverage detected