From 158ab729d24fb0b36053c169804175a4ce463a9a Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 15 Apr 2016 15:05:23 +0800 Subject: [PATCH] fix #56 show server yml config file. Signed-off-by: Bo-Yi Wu --- README.md | 3 +++ config/config.yml | 1 + gorush/config.go | 6 ++++-- gorush/const.go | 2 +- gorush/server.go | 5 +++++ gorush/server_test.go | 11 +++++++++++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0be27a4..eb27fba 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ A push notification server using [Gin](https://github.com/gin-gonic/gin) framewo * Support [HTTP/2](https://http2.github.io/) or HTTP/1.1 protocol. * Support notification queue and multiple workers. * Support `/api/stat/app` show notification success and failure counts. +* Support `/api/config` show your yml config. See the [YAML config example](config/config.yml): @@ -38,6 +39,7 @@ api: push_uri: "/api/push" stat_go_uri: "/api/stat/go" stat_app_uri: "/api/stat/app" + config_uri: "/api/config" android: enabled: true @@ -115,6 +117,7 @@ Gorush support the following API. * **GET** `/api/stat/go` Golang cpu, memory, gc, etc information. Thanks for [golang-stats-api-handler](https://github.com/fukata/golang-stats-api-handler). * **GET** `/api/stat/app` show notification success and failure counts. +* **GET** `/api/config` show server yml config file. * **POST** `/api/push` push ios and android notifications. ### GET /api/stat/go diff --git a/config/config.yml b/config/config.yml index 570a329..6744425 100644 --- a/config/config.yml +++ b/config/config.yml @@ -12,6 +12,7 @@ api: push_uri: "/api/push" stat_go_uri: "/api/stat/go" stat_app_uri: "/api/stat/app" + config_uri: "/api/config" android: enabled: true diff --git a/gorush/config.go b/gorush/config.go index 7b6ee8f..bfb8e00 100644 --- a/gorush/config.go +++ b/gorush/config.go @@ -29,9 +29,10 @@ type SectionCore struct { // SectionAPI is sub seciont of config. type SectionAPI struct { - PushURI string `yaml:"push_uri"` - StatGoURI string `yaml:"stat_go_uri"` + PushURI string `yaml:"push_uri"` + StatGoURI string `yaml:"stat_go_uri"` StatAppURI string `yaml:"stat_app_uri"` + ConfigURI string `yaml:"config_uri"` } // SectionAndroid is sub seciont of config. @@ -75,6 +76,7 @@ func BuildDefaultPushConf() ConfYaml { conf.API.PushURI = "/api/push" conf.API.StatGoURI = "/api/stat/go" conf.API.StatAppURI = "/api/stat/app" + conf.API.ConfigURI = "/api/config" // Android conf.Android.Enabled = false diff --git a/gorush/const.go b/gorush/const.go index 81bb424..b3b137c 100644 --- a/gorush/const.go +++ b/gorush/const.go @@ -2,7 +2,7 @@ package gorush const ( // Version is gorush server version. - Version = "1.0.0" + Version = "1.1.0" ) const ( diff --git a/gorush/server.go b/gorush/server.go index 6bcd617..b7a5b2c 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -55,6 +55,10 @@ func pushHandler(c *gin.Context) { }) } +func configHandler(c *gin.Context) { + c.YAML(http.StatusCreated, PushConf) +} + func routerEngine() *gin.Engine { // set server mode gin.SetMode(PushConf.Core.Mode) @@ -69,6 +73,7 @@ func routerEngine() *gin.Engine { r.GET(PushConf.API.StatGoURI, api.StatusHandler) r.GET(PushConf.API.StatAppURI, appStatusHandler) + r.GET(PushConf.API.ConfigURI, configHandler) r.POST(PushConf.API.PushURI, pushHandler) r.GET("/", rootHandler) diff --git a/gorush/server_test.go b/gorush/server_test.go index b90757e..6899d5a 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -103,6 +103,17 @@ func TestAPIStatusAppHandler(t *testing.T) { }) } +func TestAPIConfigHandler(t *testing.T) { + initTest() + + r := gofight.New() + + r.GET("/api/config"). + Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { + assert.Equal(t, http.StatusCreated, r.Code) + }) +} + func TestMissingNotificationsParameter(t *testing.T) { initTest()