support custom url for health URI. (#302)

* support custom url for health URI.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* fix readme

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-10-25 21:19:58 -05:00 committed by GitHub
parent 313d74c927
commit e99692717c
5 changed files with 10 additions and 1 deletions

View File

@ -101,6 +101,7 @@ api:
config_uri: "/api/config" config_uri: "/api/config"
sys_stat_uri: "/sys/stats" sys_stat_uri: "/sys/stats"
metric_uri: "/metrics" metric_uri: "/metrics"
health_uri: "/healthz"
android: android:
enabled: true enabled: true

View File

@ -44,6 +44,7 @@ api:
config_uri: "/api/config" config_uri: "/api/config"
sys_stat_uri: "/sys/stats" sys_stat_uri: "/sys/stats"
metric_uri: "/metrics" metric_uri: "/metrics"
health_uri: "/healthz"
android: android:
enabled: true enabled: true
@ -126,6 +127,7 @@ type SectionAPI struct {
ConfigURI string `yaml:"config_uri"` ConfigURI string `yaml:"config_uri"`
SysStatURI string `yaml:"sys_stat_uri"` SysStatURI string `yaml:"sys_stat_uri"`
MetricURI string `yaml:"metric_uri"` MetricURI string `yaml:"metric_uri"`
HealthURI string `yaml:"health_uri"`
} }
// SectionAndroid is sub section of config. // SectionAndroid is sub section of config.
@ -261,6 +263,7 @@ func LoadConf(confPath string) (ConfYaml, error) {
conf.API.ConfigURI = viper.GetString("api.config_uri") conf.API.ConfigURI = viper.GetString("api.config_uri")
conf.API.SysStatURI = viper.GetString("api.sys_stat_uri") conf.API.SysStatURI = viper.GetString("api.sys_stat_uri")
conf.API.MetricURI = viper.GetString("api.metric_uri") conf.API.MetricURI = viper.GetString("api.metric_uri")
conf.API.HealthURI = viper.GetString("api.health_uri")
// Android // Android
conf.Android.Enabled = viper.GetBool("android.enabled") conf.Android.Enabled = viper.GetBool("android.enabled")

View File

@ -31,6 +31,7 @@ api:
config_uri: "/api/config" config_uri: "/api/config"
sys_stat_uri: "/sys/stats" sys_stat_uri: "/sys/stats"
metric_uri: "/metrics" metric_uri: "/metrics"
health_uri: "/healthz"
android: android:
enabled: true enabled: true

View File

@ -64,6 +64,7 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
assert.Equal(suite.T(), "/api/config", suite.ConfGorushDefault.API.ConfigURI) assert.Equal(suite.T(), "/api/config", suite.ConfGorushDefault.API.ConfigURI)
assert.Equal(suite.T(), "/sys/stats", suite.ConfGorushDefault.API.SysStatURI) assert.Equal(suite.T(), "/sys/stats", suite.ConfGorushDefault.API.SysStatURI)
assert.Equal(suite.T(), "/metrics", suite.ConfGorushDefault.API.MetricURI) assert.Equal(suite.T(), "/metrics", suite.ConfGorushDefault.API.MetricURI)
assert.Equal(suite.T(), "/healthz", suite.ConfGorushDefault.API.HealthURI)
// Android // Android
assert.Equal(suite.T(), true, suite.ConfGorushDefault.Android.Enabled) assert.Equal(suite.T(), true, suite.ConfGorushDefault.Android.Enabled)
@ -131,6 +132,7 @@ func (suite *ConfigTestSuite) TestValidateConf() {
assert.Equal(suite.T(), "/api/config", suite.ConfGorush.API.ConfigURI) assert.Equal(suite.T(), "/api/config", suite.ConfGorush.API.ConfigURI)
assert.Equal(suite.T(), "/sys/stats", suite.ConfGorush.API.SysStatURI) assert.Equal(suite.T(), "/sys/stats", suite.ConfGorush.API.SysStatURI)
assert.Equal(suite.T(), "/metrics", suite.ConfGorush.API.MetricURI) assert.Equal(suite.T(), "/metrics", suite.ConfGorush.API.MetricURI)
assert.Equal(suite.T(), "/healthz", suite.ConfGorush.API.HealthURI)
// Android // Android
assert.Equal(suite.T(), true, suite.ConfGorush.Android.Enabled) assert.Equal(suite.T(), true, suite.ConfGorush.Android.Enabled)
@ -180,6 +182,7 @@ func TestLoadConfigFromEnv(t *testing.T) {
os.Setenv("GORUSH_CORE_MAX_NOTIFICATION", "200") os.Setenv("GORUSH_CORE_MAX_NOTIFICATION", "200")
os.Setenv("GORUSH_IOS_KEY_ID", "ABC123DEFG") os.Setenv("GORUSH_IOS_KEY_ID", "ABC123DEFG")
os.Setenv("GORUSH_IOS_TEAM_ID", "DEF123GHIJ") os.Setenv("GORUSH_IOS_TEAM_ID", "DEF123GHIJ")
os.Setenv("GORUSH_API_HEALTH_URI", "/healthz")
ConfGorush, err := LoadConf("config.yml") ConfGorush, err := LoadConf("config.yml")
if err != nil { if err != nil {
panic("failed to load config.yml from file") panic("failed to load config.yml from file")
@ -189,4 +192,5 @@ func TestLoadConfigFromEnv(t *testing.T) {
assert.True(t, ConfGorush.GRPC.Enabled) assert.True(t, ConfGorush.GRPC.Enabled)
assert.Equal(t, "ABC123DEFG", ConfGorush.Ios.KeyID) assert.Equal(t, "ABC123DEFG", ConfGorush.Ios.KeyID)
assert.Equal(t, "DEF123GHIJ", ConfGorush.Ios.TeamID) assert.Equal(t, "DEF123GHIJ", ConfGorush.Ios.TeamID)
assert.Equal(t, "/healthz", ConfGorush.API.HealthURI)
} }

View File

@ -118,7 +118,7 @@ func routerEngine() *gin.Engine {
r.GET(PushConf.API.SysStatURI, sysStatsHandler) r.GET(PushConf.API.SysStatURI, sysStatsHandler)
r.POST(PushConf.API.PushURI, pushHandler) r.POST(PushConf.API.PushURI, pushHandler)
r.GET(PushConf.API.MetricURI, metricsHandler) r.GET(PushConf.API.MetricURI, metricsHandler)
r.GET("/healthz", heartbeatHandler) r.GET(PushConf.API.HealthURI, heartbeatHandler)
r.GET("/version", versionHandler) r.GET("/version", versionHandler)
r.GET("/", rootHandler) r.GET("/", rootHandler)