Skip to content

Commit

Permalink
enhance: escalate ProxyHeader as a global config
Browse files Browse the repository at this point in the history
  • Loading branch information
HFO4 committed Dec 16, 2022
1 parent 9860ebb commit 82b4e29
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func main() {
}

api := routers.InitRouter()
api.TrustedPlatform = conf.SystemConfig.ProxyHeader
server := &http.Server{Handler: api}

// 收到信号后关闭服务器
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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存储端配置
Expand Down
10 changes: 5 additions & 5 deletions pkg/conf/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 跨域配置
Expand All @@ -47,8 +48,7 @@ var SSLConfig = &ssl{
}

var UnixConfig = &unix{
Listen: "",
ProxyHeader: "X-Forwarded-For",
Listen: "",
}

var OptionOverwrite = map[string]interface{}{}

0 comments on commit 82b4e29

Please sign in to comment.