feat(config): enable or disable httpd server. (#262)
This commit is contained in:
parent
ac7bd0afd3
commit
00ff0248a2
|
@ -69,6 +69,7 @@ See the [YAML config example](config/config.yml):
|
||||||
[embedmd]:# (config/config.yml yaml)
|
[embedmd]:# (config/config.yml yaml)
|
||||||
```yaml
|
```yaml
|
||||||
core:
|
core:
|
||||||
|
enabled: true # enabale httpd server
|
||||||
port: "8088" # ignore this port number if auto_tls is enabled (listen 443).
|
port: "8088" # ignore this port number if auto_tls is enabled (listen 443).
|
||||||
worker_num: 0 # default worker number is runtime.NumCPU()
|
worker_num: 0 # default worker number is runtime.NumCPU()
|
||||||
queue_num: 0 # default queue number is 8192
|
queue_num: 0 # default queue number is 8192
|
||||||
|
|
|
@ -20,6 +20,7 @@ type ConfYaml struct {
|
||||||
|
|
||||||
// SectionCore is sub section of config.
|
// SectionCore is sub section of config.
|
||||||
type SectionCore struct {
|
type SectionCore struct {
|
||||||
|
Enabled bool `yaml:"enabled"`
|
||||||
Port string `yaml:"port"`
|
Port string `yaml:"port"`
|
||||||
MaxNotification int64 `yaml:"max_notification"`
|
MaxNotification int64 `yaml:"max_notification"`
|
||||||
WorkerNum int64 `yaml:"worker_num"`
|
WorkerNum int64 `yaml:"worker_num"`
|
||||||
|
@ -128,6 +129,7 @@ func BuildDefaultPushConf() ConfYaml {
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
conf.Core.Port = "8088"
|
conf.Core.Port = "8088"
|
||||||
|
conf.Core.Enabled = true
|
||||||
conf.Core.WorkerNum = int64(runtime.NumCPU())
|
conf.Core.WorkerNum = int64(runtime.NumCPU())
|
||||||
conf.Core.QueueNum = int64(8192)
|
conf.Core.QueueNum = int64(8192)
|
||||||
conf.Core.Mode = "release"
|
conf.Core.Mode = "release"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
core:
|
core:
|
||||||
|
enabled: true # enabale httpd server
|
||||||
port: "8088" # ignore this port number if auto_tls is enabled (listen 443).
|
port: "8088" # ignore this port number if auto_tls is enabled (listen 443).
|
||||||
worker_num: 0 # default worker number is runtime.NumCPU()
|
worker_num: 0 # default worker number is runtime.NumCPU()
|
||||||
queue_num: 0 # default queue number is 8192
|
queue_num: 0 # default queue number is 8192
|
||||||
|
|
|
@ -56,6 +56,7 @@ func (suite *ConfigTestSuite) SetupTest() {
|
||||||
func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
||||||
// Core
|
// Core
|
||||||
assert.Equal(suite.T(), "8088", suite.ConfGorushDefault.Core.Port)
|
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)
|
assert.Equal(suite.T(), int64(runtime.NumCPU()), suite.ConfGorushDefault.Core.WorkerNum)
|
||||||
assert.Equal(suite.T(), int64(8192), suite.ConfGorushDefault.Core.QueueNum)
|
assert.Equal(suite.T(), int64(8192), suite.ConfGorushDefault.Core.QueueNum)
|
||||||
assert.Equal(suite.T(), "release", suite.ConfGorushDefault.Core.Mode)
|
assert.Equal(suite.T(), "release", suite.ConfGorushDefault.Core.Mode)
|
||||||
|
@ -120,6 +121,7 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
||||||
func (suite *ConfigTestSuite) TestValidateConf() {
|
func (suite *ConfigTestSuite) TestValidateConf() {
|
||||||
// Core
|
// Core
|
||||||
assert.Equal(suite.T(), "8088", suite.ConfGorush.Core.Port)
|
assert.Equal(suite.T(), "8088", suite.ConfGorush.Core.Port)
|
||||||
|
assert.Equal(suite.T(), true, suite.ConfGorush.Core.Enabled)
|
||||||
assert.Equal(suite.T(), int64(runtime.NumCPU()), suite.ConfGorush.Core.WorkerNum)
|
assert.Equal(suite.T(), int64(runtime.NumCPU()), suite.ConfGorush.Core.WorkerNum)
|
||||||
assert.Equal(suite.T(), int64(8192), suite.ConfGorush.Core.QueueNum)
|
assert.Equal(suite.T(), int64(8192), suite.ConfGorush.Core.QueueNum)
|
||||||
assert.Equal(suite.T(), "release", suite.ConfGorush.Core.Mode)
|
assert.Equal(suite.T(), "release", suite.ConfGorush.Core.Mode)
|
||||||
|
|
|
@ -255,3 +255,12 @@ func TestMetricsHandler(t *testing.T) {
|
||||||
assert.Equal(t, http.StatusOK, r.Code)
|
assert.Equal(t, http.StatusOK, r.Code)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDisabledHTTPServer(t *testing.T) {
|
||||||
|
initTest()
|
||||||
|
PushConf.Core.Enabled = false
|
||||||
|
err := RunHTTPServer()
|
||||||
|
PushConf.Core.Enabled = true
|
||||||
|
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,11 @@ import (
|
||||||
|
|
||||||
// RunHTTPServer provide run http or https protocol.
|
// RunHTTPServer provide run http or https protocol.
|
||||||
func RunHTTPServer() (err error) {
|
func RunHTTPServer() (err error) {
|
||||||
|
if !PushConf.Core.Enabled {
|
||||||
|
LogAccess.Debug("httpd server is disabled.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
LogAccess.Debug("HTTPD server is running on " + PushConf.Core.Port + " port.")
|
LogAccess.Debug("HTTPD server is running on " + PushConf.Core.Port + " port.")
|
||||||
if PushConf.Core.AutoTLS.Enabled {
|
if PushConf.Core.AutoTLS.Enabled {
|
||||||
err = gracehttp.Serve(autoTLSServer())
|
err = gracehttp.Serve(autoTLSServer())
|
||||||
|
|
|
@ -8,6 +8,11 @@ import (
|
||||||
|
|
||||||
// RunHTTPServer provide run http or https protocol.
|
// RunHTTPServer provide run http or https protocol.
|
||||||
func RunHTTPServer() (err error) {
|
func RunHTTPServer() (err error) {
|
||||||
|
if !PushConf.Core.Enabled {
|
||||||
|
LogAccess.Debug("httpd server is disabled.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if PushConf.Core.AutoTLS.Enabled {
|
if PushConf.Core.AutoTLS.Enabled {
|
||||||
s := autoTLSServer()
|
s := autoTLSServer()
|
||||||
err = s.ListenAndServeTLS("", "")
|
err = s.ListenAndServeTLS("", "")
|
||||||
|
|
Loading…
Reference in New Issue