Skip to content

Commit

Permalink
Merge pull request #57 from appleboy/config
Browse files Browse the repository at this point in the history
fix #56 show server yml config file.
  • Loading branch information
appleboy committed Apr 15, 2016
2 parents 880d34d + 158ab72 commit 3338227
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions gorush/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gorush/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package gorush

const (
// Version is gorush server version.
Version = "1.0.0"
Version = "1.1.0"
)

const (
Expand Down
5 changes: 5 additions & 0 deletions gorush/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions gorush/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 3338227

Please sign in to comment.