Support app version on api.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-09-30 10:49:52 +08:00
parent ca3ec3293d
commit b744208a29
4 changed files with 12 additions and 1 deletions

View File

@ -35,7 +35,7 @@ update:
glide update glide update
build_static: 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 build: clean
sh script/build.sh $(VERSION) sh script/build.sh $(VERSION)

View File

@ -260,6 +260,7 @@ Show success or failure counts information of notification.
```json ```json
{ {
"version": "v1.6.2",
"queue_max": 8192, "queue_max": 8192,
"queue_usage": 0, "queue_usage": 0,
"total_count": 77, "total_count": 77,

View File

@ -102,8 +102,16 @@ func TestAPIStatusAppHandler(t *testing.T) {
r := gofight.New() r := gofight.New()
appVersion := "v1.0.0"
SetVersion(appVersion)
r.GET("/api/stat/app"). r.GET("/api/stat/app").
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { 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) assert.Equal(t, http.StatusOK, r.Code)
}) })
} }

View File

@ -16,6 +16,7 @@ var Stats = stats.New()
// StatusApp is app status structure // StatusApp is app status structure
type StatusApp struct { type StatusApp struct {
Version string `json:"version"`
QueueMax int `json:"queue_max"` QueueMax int `json:"queue_max"`
QueueUsage int `json:"queue_usage"` QueueUsage int `json:"queue_usage"`
TotalCount int64 `json:"total_count"` TotalCount int64 `json:"total_count"`
@ -66,6 +67,7 @@ func InitAppStatus() error {
func appStatusHandler(c *gin.Context) { func appStatusHandler(c *gin.Context) {
result := StatusApp{} result := StatusApp{}
result.Version = GetVersion()
result.QueueMax = cap(QueueNotification) result.QueueMax = cap(QueueNotification)
result.QueueUsage = len(QueueNotification) result.QueueUsage = len(QueueNotification)
result.TotalCount = StatStorage.GetTotalCount() result.TotalCount = StatStorage.GetTotalCount()