Skip to content

Commit 2dbe594

Browse files
committed
fix(short_id): enhance GetEnableShortID to support gin context for short ID flag retrieval
1 parent 36b5481 commit 2dbe594

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

internal/base/handler/short_id.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,22 @@ import (
2323
"context"
2424

2525
"github.com/apache/answer/internal/base/constant"
26+
"github.com/gin-gonic/gin"
2627
)
2728

28-
// GetEnableShortID get language from header
29+
// GetEnableShortID get short id flag from context
2930
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)
3042
flag, ok := ctx.Value(constant.ShortIDContextKey).(bool)
3143
if ok {
3244
return flag

0 commit comments

Comments
 (0)