diff --git a/config/config.go b/config/config.go index 56edee4..d3f25cf 100644 --- a/config/config.go +++ b/config/config.go @@ -21,6 +21,7 @@ type ConfYaml struct { // SectionCore is sub section of config. type SectionCore struct { Enabled bool `yaml:"enabled"` + Address string `yaml:"address"` Port string `yaml:"port"` MaxNotification int64 `yaml:"max_notification"` WorkerNum int64 `yaml:"worker_num"` @@ -128,6 +129,7 @@ func BuildDefaultPushConf() ConfYaml { var conf ConfYaml // Core + conf.Core.Address = "" conf.Core.Port = "8088" conf.Core.Enabled = true conf.Core.WorkerNum = int64(runtime.NumCPU()) diff --git a/config/config_test.go b/config/config_test.go index 1a5200c..6ce9c45 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -55,6 +55,7 @@ func (suite *ConfigTestSuite) SetupTest() { func (suite *ConfigTestSuite) TestValidateConfDefault() { // Core + assert.Equal(suite.T(), "", suite.ConfGorushDefault.Core.Address) assert.Equal(suite.T(), "8088", suite.ConfGorushDefault.Core.Port) assert.Equal(suite.T(), true, suite.ConfGorushDefault.Core.Enabled) assert.Equal(suite.T(), int64(runtime.NumCPU()), suite.ConfGorushDefault.Core.WorkerNum) diff --git a/gorush/server_unix.go b/gorush/server_unix.go index e9d870b..9031e1b 100644 --- a/gorush/server_unix.go +++ b/gorush/server_unix.go @@ -36,13 +36,13 @@ func RunHTTPServer() (err error) { } err = gracehttp.Serve(&http.Server{ - Addr: ":" + PushConf.Core.Port, + Addr: PushConf.Core.Address + ":" + PushConf.Core.Port, Handler: routerEngine(), TLSConfig: config, }) } else { err = gracehttp.Serve(&http.Server{ - Addr: ":" + PushConf.Core.Port, + Addr: PushConf.Core.Address + ":" + PushConf.Core.Port, Handler: routerEngine(), }) } diff --git a/gorush/server_windows.go b/gorush/server_windows.go index c83fe61..e6ce8c6 100644 --- a/gorush/server_windows.go +++ b/gorush/server_windows.go @@ -17,9 +17,9 @@ func RunHTTPServer() (err error) { s := autoTLSServer() err = s.ListenAndServeTLS("", "") } else if PushConf.Core.SSL && PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" { - err = http.ListenAndServeTLS(":"+PushConf.Core.Port, PushConf.Core.CertPath, PushConf.Core.KeyPath, routerEngine()) + err = http.ListenAndServeTLS(PushConf.Core.Address+":"+PushConf.Core.Port, PushConf.Core.CertPath, PushConf.Core.KeyPath, routerEngine()) } else { - err = http.ListenAndServe(":"+PushConf.Core.Port, routerEngine()) + err = http.ListenAndServe(PushConf.Core.Address+":"+PushConf.Core.Port, routerEngine()) } return diff --git a/main.go b/main.go index 1772141..3c80f6e 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,7 @@ var usageStr = ` Usage: gorush [options] Server Options: + -A, --address
Address to bind (default: any) -p, --port