Skip to content

Commit

Permalink
Support app version on api.
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Sep 30, 2016
1 parent ca3ec32 commit b744208
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ update:
glide update

build_static:
go build -ldflags="${EXTLDFLAGS}-s -w -X main.Version=${VERSION}" -o bin/gorush gorush.go
go build -ldflags='${EXTLDFLAGS}-s -w -X main.Version=${VERSION}' -o bin/gorush gorush.go

build: clean
sh script/build.sh $(VERSION)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ Show success or failure counts information of notification.

```json
{
"version": "v1.6.2",
"queue_max": 8192,
"queue_usage": 0,
"total_count": 77,
Expand Down
8 changes: 8 additions & 0 deletions gorush/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,16 @@ func TestAPIStatusAppHandler(t *testing.T) {

r := gofight.New()

appVersion := "v1.0.0"
SetVersion(appVersion)

r.GET("/api/stat/app").
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
data := []byte(r.Body.String())

value, _ := jsonparser.GetString(data, "version")

assert.Equal(t, appVersion, value)
assert.Equal(t, http.StatusOK, r.Code)
})
}
Expand Down
2 changes: 2 additions & 0 deletions gorush/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var Stats = stats.New()

// StatusApp is app status structure
type StatusApp struct {
Version string `json:"version"`
QueueMax int `json:"queue_max"`
QueueUsage int `json:"queue_usage"`
TotalCount int64 `json:"total_count"`
Expand Down Expand Up @@ -66,6 +67,7 @@ func InitAppStatus() error {
func appStatusHandler(c *gin.Context) {
result := StatusApp{}

result.Version = GetVersion()
result.QueueMax = cap(QueueNotification)
result.QueueUsage = len(QueueNotification)
result.TotalCount = StatStorage.GetTotalCount()
Expand Down

0 comments on commit b744208

Please sign in to comment.