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) } }