From 82b4e29a8019ac04ded51d17221abda8c3535080 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Fri, 16 Dec 2022 16:58:06 +0800 Subject: [PATCH] enhance: escalate `ProxyHeader` as a global config --- main.go | 2 +- pkg/conf/conf.go | 8 ++++---- pkg/conf/defaults.go | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index acb155a..a33e9b3 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,7 @@ func main() { } api := routers.InitRouter() + api.TrustedPlatform = conf.SystemConfig.ProxyHeader server := &http.Server{Handler: api} // 收到信号后关闭服务器 @@ -102,7 +103,6 @@ func main() { } } - api.TrustedPlatform = conf.UnixConfig.ProxyHeader util.Log().Info("Listening to %q", conf.UnixConfig.Listen) if err := RunUnix(server); err != nil { util.Log().Error("Failed to listen to %q: %s", conf.UnixConfig.Listen, err) diff --git a/pkg/conf/conf.go b/pkg/conf/conf.go index 96cc4bb..8f0109e 100644 --- a/pkg/conf/conf.go +++ b/pkg/conf/conf.go @@ -26,7 +26,8 @@ type system struct { Debug bool SessionSecret string HashIDSalt string - GracePeriod int `validate:"gte=0"` + GracePeriod int `validate:"gte=0"` + ProxyHeader string `validate:"required_with=Listen"` } type ssl struct { @@ -36,9 +37,8 @@ type ssl struct { } type unix struct { - Listen string - ProxyHeader string `validate:"required_with=Listen"` - Perm uint32 + Listen string + Perm uint32 } // slave 作为slave存储端配置 diff --git a/pkg/conf/defaults.go b/pkg/conf/defaults.go index fc5eef1..80ecc7e 100644 --- a/pkg/conf/defaults.go +++ b/pkg/conf/defaults.go @@ -18,9 +18,10 @@ var DatabaseConfig = &database{ // SystemConfig 系统公用配置 var SystemConfig = &system{ - Debug: false, - Mode: "master", - Listen: ":5212", + Debug: false, + Mode: "master", + Listen: ":5212", + ProxyHeader: "X-Forwarded-For", } // CORSConfig 跨域配置 @@ -47,8 +48,7 @@ var SSLConfig = &ssl{ } var UnixConfig = &unix{ - Listen: "", - ProxyHeader: "X-Forwarded-For", + Listen: "", } var OptionOverwrite = map[string]interface{}{}