This commit is contained in:
2025-05-09 17:54:28 +08:00
parent 8003431fdb
commit 00c2f07769
110 changed files with 11003 additions and 576 deletions

View File

@@ -0,0 +1,34 @@
package middleware
import (
"context"
"net/http"
)
type contextKey string
const (
brandKey contextKey = "brand"
platformKey contextKey = "platform"
promoteKey contextKey = "promoteKey"
)
func ReqHeaderCtxMiddleware(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
brand := r.Header.Get("X-Brand")
platform := r.Header.Get("X-Platform")
promoteValue := r.Header.Get("X-Promote-Key")
ctx := r.Context()
if brand != "" {
ctx = context.WithValue(ctx, brandKey, brand)
}
if platform != "" {
ctx = context.WithValue(ctx, platformKey, platform)
}
if promoteValue != "" {
ctx = context.WithValue(ctx, promoteKey, promoteValue)
}
r = r.WithContext(ctx)
next(w, r)
}
}