This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/answer.git


The following commit(s) were added to refs/heads/test by this push:
     new 2dbe594d fix(short_id): enhance GetEnableShortID to support gin 
context for short ID flag retrieval
2dbe594d is described below

commit 2dbe594da270b533eff2d88ff7e62316078b14de
Author: LinkinStars <[email protected]>
AuthorDate: Wed Mar 4 12:04:52 2026 +0800

    fix(short_id): enhance GetEnableShortID to support gin context for short ID 
flag retrieval
---
 internal/base/handler/short_id.go | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/internal/base/handler/short_id.go 
b/internal/base/handler/short_id.go
index 8f9a2a7e..fc0f3f33 100644
--- a/internal/base/handler/short_id.go
+++ b/internal/base/handler/short_id.go
@@ -23,10 +23,22 @@ import (
        "context"
 
        "github.com/apache/answer/internal/base/constant"
+       "github.com/gin-gonic/gin"
 )
 
-// GetEnableShortID get language from header
+// GetEnableShortID get short id flag from context
 func GetEnableShortID(ctx context.Context) bool {
+       // Check gin context first (set by ShortIDMiddleware via ctx.Set)
+       if ginCtx, ok := ctx.(*gin.Context); ok {
+               flag, ok := ginCtx.Get(constant.ShortIDFlag)
+               if ok {
+                       if flag, ok := flag.(bool); ok {
+                               return flag
+                       }
+                       return false
+               }
+       }
+       // Fallback for non-gin contexts (e.g., SitemapCron uses 
context.WithValue)
        flag, ok := ctx.Value(constant.ShortIDContextKey).(bool)
        if ok {
                return flag

Reply via email to