2025-05-09 17:54:28 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
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 != "" {
|
2025-05-09 20:26:22 +08:00
|
|
|
ctx = context.WithValue(ctx, "brand", brand)
|
2025-05-09 17:54:28 +08:00
|
|
|
}
|
|
|
|
if platform != "" {
|
2025-05-09 20:26:22 +08:00
|
|
|
ctx = context.WithValue(ctx, "platform", platform)
|
2025-05-09 17:54:28 +08:00
|
|
|
}
|
|
|
|
if promoteValue != "" {
|
2025-05-09 20:26:22 +08:00
|
|
|
ctx = context.WithValue(ctx, "promoteKey", promoteValue)
|
2025-05-09 17:54:28 +08:00
|
|
|
}
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
next(w, r)
|
|
|
|
}
|
|
|
|
}
|