fix promotion

This commit is contained in:
2025-06-20 15:12:34 +08:00
parent c062908aae
commit 9aa6913883
3 changed files with 45 additions and 4 deletions

View File

@@ -7,19 +7,22 @@ import (
const (
PlatformKey = "X-Platform"
PromoteKey = "X-Promote-Key"
)
func GlobalSourceInterceptor(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// 获取请求头 X-Platform 的值
platform := r.Header.Get(PlatformKey)
promoteValue := r.Header.Get(PromoteKey)
// 将值放入新的 context 中
ctx := r.Context()
if platform != "" {
ctx = context.WithValue(ctx, "platform", platform)
}
if promoteValue != "" {
ctx = context.WithValue(ctx, "promoteKey", promoteValue)
}
// 通过 r.WithContext 将更新后的 ctx 传递给后续的处理函数
r = r.WithContext(ctx)