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 != "" { ctx = context.WithValue(ctx, "brand", brand) } if platform != "" { ctx = context.WithValue(ctx, "platform", platform) } if promoteValue != "" { ctx = context.WithValue(ctx, "promoteKey", promoteValue) } r = r.WithContext(ctx) next(w, r) } }