Merge pull request #57 from appleboy/config

fix #56 show server yml config file.
This commit is contained in:
Bo-Yi Wu 2016-04-15 02:05:59 -05:00
commit 3338227f57
6 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -2,7 +2,7 @@ package gorush
const (
// Version is gorush server version.
Version = "1.0.0"
Version = "1.1.0"
)
const (

View File

@ -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)

View File

@ -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()