Support success or failure of notification counts information.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2016-04-15 10:24:39 +08:00
parent e6f2bf5152
commit a346f29f95
6 changed files with 104 additions and 11 deletions

View File

@@ -31,6 +31,7 @@ type SectionCore struct {
type SectionAPI struct {
PushURI string `yaml:"push_uri"`
StatGoURI string `yaml:"stat_go_uri"`
StatAppURI string `yaml:"stat_app_uri"`
}
// SectionAndroid is sub seciont of config.
@@ -72,7 +73,8 @@ func BuildDefaultPushConf() ConfYaml {
// Api
conf.API.PushURI = "/api/push"
conf.API.StatGoURI = "/api/status"
conf.API.StatGoURI = "/api/stat/go"
conf.API.StatAppURI = "/api/stat/app"
// Android
conf.Android.Enabled = false

View File

@@ -68,6 +68,7 @@ func routerEngine() *gin.Engine {
r.Use(LogMiddleware())
r.GET(PushConf.API.StatGoURI, api.StatusHandler)
r.GET(PushConf.API.StatAppURI, appStatusHandler)
r.POST(PushConf.API.PushURI, pushHandler)
r.GET("/", rootHandler)

View File

@@ -36,7 +36,7 @@ func TestRunNormalServer(t *testing.T) {
time.Sleep(5 * time.Millisecond)
assert.Error(t, RunHTTPServer())
gofight.TestRequest(t, "http://localhost:8088/api/status")
gofight.TestRequest(t, "http://localhost:8088/api/stat/go")
}
func TestRunTLSServer(t *testing.T) {
@@ -76,12 +76,12 @@ func TestRootHandler(t *testing.T) {
})
}
func TestAPIStatusHandler(t *testing.T) {
func TestAPIStatusGoHandler(t *testing.T) {
initTest()
r := gofight.New()
r.GET("/api/status").
r.GET("/api/stat/go").
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
data := []byte(r.Body.String())
@@ -92,6 +92,17 @@ func TestAPIStatusHandler(t *testing.T) {
})
}
func TestAPIStatusAppHandler(t *testing.T) {
initTest()
r := gofight.New()
r.GET("/api/stat/app").
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code)
})
}
func TestMissingNotificationsParameter(t *testing.T) {
initTest()

View File

@@ -1,6 +1,8 @@
package gorush
import (
"github.com/gin-gonic/gin"
"net/http"
"sync/atomic"
)
@@ -49,3 +51,17 @@ func addAndroidSuccess(count int64) {
func addAndroidError(count int64) {
atomic.AddInt64(&RushStatus.Android.PushError, count)
}
func appStatusHandler(c *gin.Context) {
result := StatusApp{}
result.QueueMax = cap(QueueNotification)
result.QueueUsage = len(QueueNotification)
result.TotalCount = atomic.LoadInt64(&RushStatus.TotalCount)
result.Ios.PushSuccess = atomic.LoadInt64(&RushStatus.Ios.PushSuccess)
result.Ios.PushError = atomic.LoadInt64(&RushStatus.Ios.PushError)
result.Android.PushSuccess = atomic.LoadInt64(&RushStatus.Android.PushSuccess)
result.Android.PushError = atomic.LoadInt64(&RushStatus.Android.PushError)
c.JSON(http.StatusOK, result)
}