diff --git a/README.md b/README.md index 9891cc7..b0298eb 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ api: config_uri: "/api/config" sys_stat_uri: "/sys/stats" metric_uri: "/metrics" + health_uri: "/healthz" android: enabled: true diff --git a/config/config.go b/config/config.go index b5d11bc..e8103cc 100644 --- a/config/config.go +++ b/config/config.go @@ -44,6 +44,7 @@ api: config_uri: "/api/config" sys_stat_uri: "/sys/stats" metric_uri: "/metrics" + health_uri: "/healthz" android: enabled: true @@ -126,6 +127,7 @@ type SectionAPI struct { ConfigURI string `yaml:"config_uri"` SysStatURI string `yaml:"sys_stat_uri"` MetricURI string `yaml:"metric_uri"` + HealthURI string `yaml:"health_uri"` } // 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.SysStatURI = viper.GetString("api.sys_stat_uri") conf.API.MetricURI = viper.GetString("api.metric_uri") + conf.API.HealthURI = viper.GetString("api.health_uri") // Android conf.Android.Enabled = viper.GetBool("android.enabled") diff --git a/config/config.yml b/config/config.yml index 4f67b57..44acfa3 100644 --- a/config/config.yml +++ b/config/config.yml @@ -31,6 +31,7 @@ api: config_uri: "/api/config" sys_stat_uri: "/sys/stats" metric_uri: "/metrics" + health_uri: "/healthz" android: enabled: true diff --git a/config/config_test.go b/config/config_test.go index 0f56add..6c27c69 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -64,6 +64,7 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() { assert.Equal(suite.T(), "/api/config", suite.ConfGorushDefault.API.ConfigURI) assert.Equal(suite.T(), "/sys/stats", suite.ConfGorushDefault.API.SysStatURI) assert.Equal(suite.T(), "/metrics", suite.ConfGorushDefault.API.MetricURI) + assert.Equal(suite.T(), "/healthz", suite.ConfGorushDefault.API.HealthURI) // Android 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(), "/sys/stats", suite.ConfGorush.API.SysStatURI) assert.Equal(suite.T(), "/metrics", suite.ConfGorush.API.MetricURI) + assert.Equal(suite.T(), "/healthz", suite.ConfGorush.API.HealthURI) // Android 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_IOS_KEY_ID", "ABC123DEFG") os.Setenv("GORUSH_IOS_TEAM_ID", "DEF123GHIJ") + os.Setenv("GORUSH_API_HEALTH_URI", "/healthz") ConfGorush, err := LoadConf("config.yml") if err != nil { panic("failed to load config.yml from file") @@ -189,4 +192,5 @@ func TestLoadConfigFromEnv(t *testing.T) { assert.True(t, ConfGorush.GRPC.Enabled) assert.Equal(t, "ABC123DEFG", ConfGorush.Ios.KeyID) assert.Equal(t, "DEF123GHIJ", ConfGorush.Ios.TeamID) + assert.Equal(t, "/healthz", ConfGorush.API.HealthURI) } diff --git a/gorush/server.go b/gorush/server.go index 1bea92d..1f3c3e7 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -118,7 +118,7 @@ func routerEngine() *gin.Engine { r.GET(PushConf.API.SysStatURI, sysStatsHandler) r.POST(PushConf.API.PushURI, pushHandler) r.GET(PushConf.API.MetricURI, metricsHandler) - r.GET("/healthz", heartbeatHandler) + r.GET(PushConf.API.HealthURI, heartbeatHandler) r.GET("/version", versionHandler) r.GET("/", rootHandler)