Initial proxy setting for web server.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
e784ae538a
commit
4a431243df
|
@ -26,6 +26,7 @@ type SectionCore struct {
|
||||||
SSL bool `yaml:"ssl"`
|
SSL bool `yaml:"ssl"`
|
||||||
CertPath string `yaml:"cert_path"`
|
CertPath string `yaml:"cert_path"`
|
||||||
KeyPath string `yaml:"key_path"`
|
KeyPath string `yaml:"key_path"`
|
||||||
|
HTTPProxy string `yaml:"http_proxy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SectionAPI is sub seciont of config.
|
// SectionAPI is sub seciont of config.
|
||||||
|
@ -94,6 +95,7 @@ func BuildDefaultPushConf() ConfYaml {
|
||||||
conf.Core.CertPath = "cert.pem"
|
conf.Core.CertPath = "cert.pem"
|
||||||
conf.Core.KeyPath = "key.pem"
|
conf.Core.KeyPath = "key.pem"
|
||||||
conf.Core.MaxNotification = 100
|
conf.Core.MaxNotification = 100
|
||||||
|
conf.Core.HTTPProxy = ""
|
||||||
|
|
||||||
// Api
|
// Api
|
||||||
conf.API.PushURI = "/api/push"
|
conf.API.PushURI = "/api/push"
|
||||||
|
|
|
@ -7,6 +7,7 @@ core:
|
||||||
ssl: false
|
ssl: false
|
||||||
cert_path: "cert.pem"
|
cert_path: "cert.pem"
|
||||||
key_path: "key.pem"
|
key_path: "key.pem"
|
||||||
|
http_proxy: ""
|
||||||
|
|
||||||
api:
|
api:
|
||||||
push_uri: "/api/push"
|
push_uri: "/api/push"
|
||||||
|
|
|
@ -62,6 +62,7 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
||||||
assert.Equal(suite.T(), "cert.pem", suite.ConfGorushDefault.Core.CertPath)
|
assert.Equal(suite.T(), "cert.pem", suite.ConfGorushDefault.Core.CertPath)
|
||||||
assert.Equal(suite.T(), "key.pem", suite.ConfGorushDefault.Core.KeyPath)
|
assert.Equal(suite.T(), "key.pem", suite.ConfGorushDefault.Core.KeyPath)
|
||||||
assert.Equal(suite.T(), 100, suite.ConfGorushDefault.Core.MaxNotification)
|
assert.Equal(suite.T(), 100, suite.ConfGorushDefault.Core.MaxNotification)
|
||||||
|
assert.Equal(suite.T(), "", suite.ConfGorushDefault.Core.HTTPProxy)
|
||||||
|
|
||||||
// Api
|
// Api
|
||||||
assert.Equal(suite.T(), "/api/push", suite.ConfGorushDefault.API.PushURI)
|
assert.Equal(suite.T(), "/api/push", suite.ConfGorushDefault.API.PushURI)
|
||||||
|
@ -107,6 +108,7 @@ func (suite *ConfigTestSuite) TestValidateConf() {
|
||||||
assert.Equal(suite.T(), "cert.pem", suite.ConfGorush.Core.CertPath)
|
assert.Equal(suite.T(), "cert.pem", suite.ConfGorush.Core.CertPath)
|
||||||
assert.Equal(suite.T(), "key.pem", suite.ConfGorush.Core.KeyPath)
|
assert.Equal(suite.T(), "key.pem", suite.ConfGorush.Core.KeyPath)
|
||||||
assert.Equal(suite.T(), 100, suite.ConfGorush.Core.MaxNotification)
|
assert.Equal(suite.T(), 100, suite.ConfGorush.Core.MaxNotification)
|
||||||
|
assert.Equal(suite.T(), "", suite.ConfGorush.Core.HTTPProxy)
|
||||||
|
|
||||||
// Api
|
// Api
|
||||||
assert.Equal(suite.T(), "/api/push", suite.ConfGorush.API.PushURI)
|
assert.Equal(suite.T(), "/api/push", suite.ConfGorush.API.PushURI)
|
||||||
|
|
26
gorush.go
26
gorush.go
|
@ -103,17 +103,6 @@ func main() {
|
||||||
// set default parameters.
|
// set default parameters.
|
||||||
gorush.PushConf = config.BuildDefaultPushConf()
|
gorush.PushConf = config.BuildDefaultPushConf()
|
||||||
|
|
||||||
// set http proxy for GCM
|
|
||||||
if proxy != "" {
|
|
||||||
err = gorush.SetProxy(proxy)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Set Proxy error: '%v'", err)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// load user define config.
|
// load user define config.
|
||||||
if configFile != "" {
|
if configFile != "" {
|
||||||
gorush.PushConf, err = config.LoadConfYaml(configFile)
|
gorush.PushConf, err = config.LoadConfYaml(configFile)
|
||||||
|
@ -148,6 +137,21 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set http proxy for GCM
|
||||||
|
if proxy != "" {
|
||||||
|
err = gorush.SetProxy(proxy)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
gorush.LogError.Fatal("Set Proxy error: ", err)
|
||||||
|
}
|
||||||
|
} else if gorush.PushConf.Core.HTTPProxy != "" {
|
||||||
|
err = gorush.SetProxy(gorush.PushConf.Core.HTTPProxy)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
gorush.LogError.Fatal("Set Proxy error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// send android notification
|
// send android notification
|
||||||
if opts.Android.Enabled {
|
if opts.Android.Enabled {
|
||||||
gorush.PushConf.Android.Enabled = opts.Android.Enabled
|
gorush.PushConf.Android.Enabled = opts.Android.Enabled
|
||||||
|
|
|
@ -127,6 +127,7 @@ func SetProxy(proxy string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
|
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
|
||||||
|
LogAccess.Debug("Set http proxy as " + proxy)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue