From eb32e593c802dcf0c1edc69576857edc4a2865fa Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 7 Apr 2016 14:16:59 +0800 Subject: [PATCH 1/9] add request log. Signed-off-by: Bo-Yi Wu --- gorush/config.go | 2 ++ gorush/log.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ gorush/server.go | 1 + 3 files changed, 60 insertions(+) diff --git a/gorush/config.go b/gorush/config.go index 851f9d0..087a7ff 100644 --- a/gorush/config.go +++ b/gorush/config.go @@ -41,6 +41,7 @@ type SectionIos struct { } type SectionLog struct { + Format string `yaml:"format"` AccessLog string `yaml:"access_log"` AccessLevel string `yaml:"access_level"` ErrorLog string `yaml:"error_log"` @@ -73,6 +74,7 @@ func BuildDefaultPushConf() ConfYaml { conf.Ios.Production = false // log + conf.Log.Format = "string" conf.Log.AccessLog = "stdout" conf.Log.AccessLevel = "debug" conf.Log.ErrorLog = "stderr" diff --git a/gorush/log.go b/gorush/log.go index 41157fd..9b731cc 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -1,11 +1,34 @@ package gopush import ( + "encoding/json" "errors" + "fmt" "github.com/Sirupsen/logrus" + "github.com/gin-gonic/gin" "os" ) +var ( + green = string([]byte{27, 91, 57, 55, 59, 52, 50, 109}) + white = string([]byte{27, 91, 57, 48, 59, 52, 55, 109}) + yellow = string([]byte{27, 91, 57, 55, 59, 52, 51, 109}) + red = string([]byte{27, 91, 57, 55, 59, 52, 49, 109}) + blue = string([]byte{27, 91, 57, 55, 59, 52, 52, 109}) + magenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109}) + cyan = string([]byte{27, 91, 57, 55, 59, 52, 54, 109}) + reset = string([]byte{27, 91, 48, 109}) +) + +type LogReq struct { + Time string `json:"time"` + URI string `json:"uri"` + Method string `json:"method"` + IP string `json:"ip"` + ContentType string `json:"content_type"` + Agent string `json:"agent"` +} + func InitLog() error { var err error @@ -74,3 +97,37 @@ func SetLogLevel(log *logrus.Logger, levelString string) error { return nil } + +func LogRequest(uri, method, ip string, contentType string, agent string) { + var output string + log := &LogReq{ + URI: uri, + Method: method, + IP: ip, + ContentType: contentType, + Agent: agent, + } + + if PushConf.Log.Format == "json" { + logJson, err := json.Marshal(log) + + if err != nil { + LogError.Error("Marshaling JSON error") + return + } + + output = string(logJson) + } else { + // format is string + output = fmt.Sprintf("|%s header %s| %s %s %s %s %s", magenta, reset, log.Method, log.URI, log.IP, log.ContentType, log.Agent) + } + + LogAccess.Info(output) +} + +func LogMiddleware() gin.HandlerFunc { + return func(c *gin.Context) { + LogRequest(c.Request.URL.Path, c.Request.Method, c.ClientIP(), c.ContentType(), c.Request.Header.Get("User-Agent")) + c.Next() + } +} diff --git a/gorush/server.go b/gorush/server.go index e325cf9..af95c2a 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -48,6 +48,7 @@ func GetMainEngine() *gin.Engine { r.Use(gin.Logger()) r.Use(gin.Recovery()) r.Use(VersionMiddleware()) + r.Use(LogMiddleware()) r.GET(PushConf.Api.StatGoUri, api.StatusHandler) r.POST(PushConf.Api.PushUri, pushHandler) From 731d884837b96607e8ee9b8aba1d814bb15a9e9c Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 7 Apr 2016 14:42:38 +0800 Subject: [PATCH 2/9] update unit testing. Signed-off-by: Bo-Yi Wu --- .gitignore | 2 +- gorush/log.go | 3 +-- gorush/log/.gitkeep | 0 gorush/log_test.go | 2 +- gorush/server_test.go | 3 +++ 5 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 gorush/log/.gitkeep diff --git a/.gitignore b/.gitignore index 891024d..30aa775 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,4 @@ config.yaml bin/* .DS_Store coverage.out -logs/* +gopush/log/*.log diff --git a/gorush/log.go b/gorush/log.go index 9b731cc..f4cd3f8 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -21,7 +21,6 @@ var ( ) type LogReq struct { - Time string `json:"time"` URI string `json:"uri"` Method string `json:"method"` IP string `json:"ip"` @@ -98,7 +97,7 @@ func SetLogLevel(log *logrus.Logger, levelString string) error { return nil } -func LogRequest(uri, method, ip string, contentType string, agent string) { +func LogRequest(uri string, method string, ip string, contentType string, agent string) { var output string log := &LogReq{ URI: uri, diff --git a/gorush/log/.gitkeep b/gorush/log/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/gorush/log_test.go b/gorush/log_test.go index 42ecb76..dd08f3d 100644 --- a/gorush/log_test.go +++ b/gorush/log_test.go @@ -25,7 +25,7 @@ func TestSetLogOut(t *testing.T) { err = SetLogOut(log, "stderr") assert.Nil(t, err) - err = SetLogOut(log, "access.log") + err = SetLogOut(log, "log/access.log") assert.Nil(t, err) // missing create logs folder. diff --git a/gorush/server_test.go b/gorush/server_test.go index ac1b72f..fb8af9f 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -62,6 +62,9 @@ func TestRootHandler(t *testing.T) { r := gofight.New() + // log for json + PushConf.Log.Format = "json" + r.GET("/"). Run(GetMainEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { data := []byte(r.Body.String()) From 5c9802bc9f321e6f1c28cb2980fb8fb5f3c0b026 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 7 Apr 2016 16:09:43 +0800 Subject: [PATCH 3/9] update readme. Signed-off-by: Bo-Yi Wu --- README.md | 41 ++++++++++++++++++++++++++++++++++++++++- config/config.yaml | 1 + 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f3321fa..759bd41 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,48 @@ # Gopush -A push notification server written in Go (Golang). +A push notification server using [Gin](https://github.com/gin-gonic/gin) framework written in Go (Golang). [![Build Status](https://travis-ci.org/appleboy/gofight.svg?branch=master)](https://travis-ci.org/appleboy/gofight) [![Coverage Status](https://coveralls.io/repos/github/appleboy/gopush/badge.svg?branch=master)](https://coveralls.io/github/appleboy/gopush?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/gopush)](https://goreportcard.com/report/github.com/appleboy/gopush) [![codebeat badge](https://codebeat.co/badges/ee01d852-b5e8-465a-ad93-631d738818ff)](https://codebeat.co/projects/github-com-appleboy-gopush) +## Feature + +* Support [Google Cloud Message](https://developers.google.com/cloud-messaging/) using [go-gcm](https://github.com/google/go-gcm) library for Android. +* Support [HTTP/2](https://http2.github.io/) Apple Push Notification Service using [apns2](https://github.com/sideshow/apns2) library. +* Support [YAML](https://github.com/go-yaml/yaml) configuration. + +See the [YAML config eample](config/config.yaml): + +```yaml +core: + port: "8088" + notification_max: 100 + mode: "release" + ssl: false + cert_path: "cert.pem" + key_path: "key.pem" + +api: + push_uri: "/api/push" + stat_go_uri: "/api/status" + +android: + enabled: false + apikey: "" + +ios: + enabled: false + pem_cert_path: "cert.pem" + pem_key_path: "key.pem" + production: false + +log: + format: "string" # string or json + access_log: "stdout" + access_level: "debug" + error_log: "stderr" + error_level: "error" +``` + ## License Copyright 2016 Bo-Yi Wu [@appleboy](https://twitter.com/appleboy). diff --git a/config/config.yaml b/config/config.yaml index b89d37f..04c7049 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -21,6 +21,7 @@ ios: production: false log: + format: "string" # string or json access_log: "stdout" access_level: "debug" error_log: "stderr" From 227c8ff582cbe337e6e6ced06a43fd5dd6514c38 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 8 Apr 2016 15:31:58 +0800 Subject: [PATCH 4/9] Support ios LocArgs. Signed-off-by: Bo-Yi Wu --- gorush/notification.go | 10 +++------- gorush/notification_test.go | 3 +++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/gorush/notification.go b/gorush/notification.go index 7fa21c4..f98b10e 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -67,9 +67,6 @@ type RequestPushNotification struct { URLArgs []string `json:"url-args,omitempty"` Extend []ExtendJSON `json:"extend,omitempty"` Alert Alert `json:"alert,omitempty"` - - // meta - IDs []uint64 `json:"seq_id,omitempty"` } func CheckPushConf() error { @@ -178,10 +175,9 @@ func GetIOSNotification(req RequestPushNotification) *apns.Notification { payload.AlertTitleLocKey(req.Alert.TitleLocKey) } - // Need send PR to apns2 repo. - // if len(req.Alert.LocArgs) > 0 { - // payload.AlertLocArgs(req.Alert.LocArgs) - // } + if len(req.Alert.LocArgs) > 0 { + payload.AlertLocArgs(req.Alert.LocArgs) + } if len(req.Alert.TitleLocArgs) > 0 { payload.AlertTitleLocArgs(req.Alert.TitleLocArgs) diff --git a/gorush/notification_test.go b/gorush/notification_test.go index 45173f4..ba5f897 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -156,6 +156,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) { aps := dat["aps"].(map[string]interface{}) alert := aps["alert"].(map[string]interface{}) titleLocArgs := alert["title-loc-args"].([]interface{}) + locArgs := alert["loc-args"].([]interface{}) assert.Equal(t, test, action) assert.Equal(t, test, actionLocKey) @@ -166,6 +167,8 @@ func TestIOSAlertNotificationStructure(t *testing.T) { assert.Equal(t, test, titleLocKey) assert.Contains(t, titleLocArgs, "a") assert.Contains(t, titleLocArgs, "b") + assert.Contains(t, locArgs, "a") + assert.Contains(t, locArgs, "b") } func TestAndroidNotificationStructure(t *testing.T) { From 44b7e2c18735c4b6e0529beb27bdf2e2a23f0ded Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 8 Apr 2016 16:56:32 +0800 Subject: [PATCH 5/9] support ios push log. Signed-off-by: Bo-Yi Wu --- gorush/const.go | 5 ++ gorush/log.go | 103 +++++++++++++++++++++++++++++++++++++---- gorush/notification.go | 13 +++++- 3 files changed, 109 insertions(+), 12 deletions(-) diff --git a/gorush/const.go b/gorush/const.go index 55e4ecd..6ffb1ff 100644 --- a/gorush/const.go +++ b/gorush/const.go @@ -8,3 +8,8 @@ const ( PlatFormIos = iota + 1 PlatFormAndroid ) + +const ( + StatusSucceededPush = "succeeded-push" + StatusFailedPush = "failed-push" +) diff --git a/gorush/log.go b/gorush/log.go index f4cd3f8..ad07a40 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -7,6 +7,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" "os" + // "time" ) var ( @@ -28,6 +29,29 @@ type LogReq struct { Agent string `json:"agent"` } +type LogPushEntry struct { + Type string `json:"type"` + Platform string `json:"platform"` + Token string `json:"token"` + Message string `json:"message"` + Error string `json:"error"` + + // Android + To string `json:"to,omitempty"` + CollapseKey string `json:"collapse_key,omitempty"` + DelayWhileIdle bool `json:"delay_while_idle,omitempty"` + TimeToLive uint `json:"time_to_live,omitempty"` + RestrictedPackageName string `json:"restricted_package_name,omitempty"` + DryRun bool `json:"dry_run,omitempty"` + + // iOS + ApnsID string `json:"apns_id,omitempty"` + Topic string `json:"topic,omitempty"` + Badge int `json:"badge,omitempty"` + Sound string `json:"sound,omitempty"` + Category string `json:"category,omitempty"` +} + func InitLog() error { var err error @@ -37,13 +61,15 @@ func InitLog() error { LogError = logrus.New() LogAccess.Formatter = &logrus.TextFormatter{ - ForceColors: true, - FullTimestamp: true, + TimestampFormat: "2006/01/02 - 15:04:05", + ForceColors: true, + FullTimestamp: true, } LogError.Formatter = &logrus.TextFormatter{ - ForceColors: true, - FullTimestamp: true, + TimestampFormat: "2006/01/02 - 15:04:05", + ForceColors: true, + FullTimestamp: true, } // set logger @@ -108,12 +134,7 @@ func LogRequest(uri string, method string, ip string, contentType string, agent } if PushConf.Log.Format == "json" { - logJson, err := json.Marshal(log) - - if err != nil { - LogError.Error("Marshaling JSON error") - return - } + logJson, _ := json.Marshal(log) output = string(logJson) } else { @@ -124,6 +145,68 @@ func LogRequest(uri string, method string, ip string, contentType string, agent LogAccess.Info(output) } +func colorForPlatForm(platform int) string { + switch platform { + case PlatFormIos: + return blue + case PlatFormAndroid: + return cyan + default: + return reset + } +} + +func typeForPlatForm(platform int) string { + switch platform { + case PlatFormIos: + return "ios" + case PlatFormAndroid: + return "android" + default: + return "" + } +} + +func LogPush(status, token string, req RequestPushNotification, errPush error) { + var plat, platColor, output string + + platColor = colorForPlatForm(req.Platform) + plat = typeForPlatForm(req.Platform) + + errMsg := "" + if errPush != nil { + errMsg = errPush.Error() + } + + log := &LogPushEntry{ + Type: status, + Platform: plat, + Token: token, + Message: req.Message, + Error: errMsg, + } + + if PushConf.Log.Format == "json" { + logJson, _ := json.Marshal(log) + + output = string(logJson) + } else { + switch status { + case StatusSucceededPush: + output = fmt.Sprintf("|%s %s %s| %s%s%s [%s] %s", green, log.Type, reset, platColor, log.Platform, reset, log.Token, log.Message) + case StatusFailedPush: + output = fmt.Sprintf("|%s %s %s| %s%s%s [%s] | %s | Error Message: %s", red, log.Type, reset, platColor, log.Platform, reset, log.Token, log.Message, log.Error) + } + } + + switch status { + case StatusSucceededPush: + LogAccess.Info(string(output)) + case StatusFailedPush: + LogError.Error(string(output)) + } +} + func LogMiddleware() gin.HandlerFunc { return func(c *gin.Context) { LogRequest(c.Request.URL.Path, c.Request.Method, c.ClientIP(), c.ContentType(), c.Request.Header.Get("User-Agent")) diff --git a/gorush/notification.go b/gorush/notification.go index f98b10e..6619bd9 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -229,13 +229,22 @@ func PushToIOS(req RequestPushNotification) bool { res, err := ApnsClient.Push(notification) if err != nil { - log.Println("There was an error: ", err) + // apns server error + LogPush(StatusFailedPush, token, req, err) + + return false + } + + if res.StatusCode != 200 { + // error message: + // ref: https://github.com/sideshow/apns2/blob/master/response.go#L14-L65 + LogPush(StatusFailedPush, token, req, errors.New(res.Reason)) return false } if res.Sent() { - log.Println("APNs ID:", res.ApnsID) + LogPush(StatusSucceededPush, token, req, nil) } } From 1fd41ca503c6dba3cf5764fecd972d069f10beb1 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 8 Apr 2016 18:11:36 +0800 Subject: [PATCH 6/9] support android push log. Signed-off-by: Bo-Yi Wu --- gorush/log.go | 2 +- gorush/notification.go | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gorush/log.go b/gorush/log.go index ad07a40..e614045 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -150,7 +150,7 @@ func colorForPlatForm(platform int) string { case PlatFormIos: return blue case PlatFormAndroid: - return cyan + return yellow default: return reset } diff --git a/gorush/notification.go b/gorush/notification.go index 6619bd9..a0e514f 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -2,11 +2,11 @@ package gopush import ( "errors" + "fmt" "github.com/google/go-gcm" apns "github.com/sideshow/apns2" "github.com/sideshow/apns2/certificate" "github.com/sideshow/apns2/payload" - "log" ) type ExtendJSON struct { @@ -96,7 +96,7 @@ func InitAPNSClient() error { CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemKeyPath, "") if err != nil { - log.Println("Cert Error:", err) + LogError.Error("Cert Error:", err.Error()) return err } @@ -310,22 +310,22 @@ func PushToAndroid(req RequestPushNotification) bool { res, err := gcm.SendHttp(PushConf.Android.ApiKey, notification) - log.Printf("Success count: %d, Failure count: %d", res.Success, res.Failure) - if err != nil { - log.Println("GCM Server Error Message: " + err.Error()) + // GCM server error + LogError.Error("GCM server error: " + err.Error()) return false } - if res.Error != "" { - log.Println("GCM Http Error Message: " + res.Error) + LogAccess.Debug(fmt.Sprintf("Android Success count: %d, Failure count: %d", res.Success, res.Failure)) - return false - } + for k, result := range res.Results { + if result.Error != "" { + LogPush(StatusFailedPush, req.Tokens[k], req, errors.New(result.Error)) + continue + } - if res.Success > 0 { - return true + LogPush(StatusSucceededPush, req.Tokens[k], req, nil) } return true From b71b4277865cfae8037f95fd7c2376d8b8f1f279 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 8 Apr 2016 19:31:47 +0800 Subject: [PATCH 7/9] update testing. Signed-off-by: Bo-Yi Wu --- gorush/log_test.go | 12 ++++++++++++ gorush/server_test.go | 2 ++ 2 files changed, 14 insertions(+) diff --git a/gorush/log_test.go b/gorush/log_test.go index dd08f3d..1229a26 100644 --- a/gorush/log_test.go +++ b/gorush/log_test.go @@ -75,3 +75,15 @@ func TestErrorLogPath(t *testing.T) { assert.NotNil(t, InitLog()) } + +func TestPlatFormType(t *testing.T) { + assert.Equal(t, "ios", typeForPlatForm(PlatFormIos)) + assert.Equal(t, "android", typeForPlatForm(PlatFormAndroid)) + assert.Equal(t, "", typeForPlatForm(10000)) +} + +func TestPlatFormColor(t *testing.T) { + assert.Equal(t, blue, colorForPlatForm(PlatFormIos)) + assert.Equal(t, yellow, colorForPlatForm(PlatFormAndroid)) + assert.Equal(t, reset, colorForPlatForm(1000000)) +} diff --git a/gorush/server_test.go b/gorush/server_test.go index fb8af9f..1f69eab 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -205,6 +205,8 @@ func TestAndroidPushHandler(t *testing.T) { PushConf.Android.Enabled = true PushConf.Android.ApiKey = os.Getenv("ANDROID_API_KEY") + // log for json + PushConf.Log.Format = "json" android_token := os.Getenv("ANDROID_TEST_TOKEN") From a6f0de8029cead2b28306bdc03652a2f812977c9 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 8 Apr 2016 19:34:18 +0800 Subject: [PATCH 8/9] remove debug message. Signed-off-by: Bo-Yi Wu --- gorush/server.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/gorush/server.go b/gorush/server.go index af95c2a..d1359a4 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -3,7 +3,6 @@ package gopush import ( api "github.com/appleboy/gin-status-api" "github.com/gin-gonic/gin" - "log" "net/http" ) @@ -25,7 +24,6 @@ func pushHandler(c *gin.Context) { var form RequestPushNotification if err := c.BindJSON(&form); err != nil { - log.Println(err) AbortWithError(c, http.StatusBadRequest, "Bad input request, please refer to README guide.") return } From 9c7aef45334aa2ce31cd988e061dfa15a9a30783 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 9 Apr 2016 10:26:55 +0800 Subject: [PATCH 9/9] update code format. Signed-off-by: Bo-Yi Wu --- gorush/log.go | 24 +++++++++++++++++++++--- gorush/server_test.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/gorush/log.go b/gorush/log.go index e614045..749d5ce 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -139,7 +139,14 @@ func LogRequest(uri string, method string, ip string, contentType string, agent output = string(logJson) } else { // format is string - output = fmt.Sprintf("|%s header %s| %s %s %s %s %s", magenta, reset, log.Method, log.URI, log.IP, log.ContentType, log.Agent) + output = fmt.Sprintf("|%s header %s| %s %s %s %s %s", + magenta, reset, + log.Method, + log.URI, + log.IP, + log.ContentType, + log.Agent, + ) } LogAccess.Info(output) @@ -193,9 +200,20 @@ func LogPush(status, token string, req RequestPushNotification, errPush error) { } else { switch status { case StatusSucceededPush: - output = fmt.Sprintf("|%s %s %s| %s%s%s [%s] %s", green, log.Type, reset, platColor, log.Platform, reset, log.Token, log.Message) + output = fmt.Sprintf("|%s %s %s| %s%s%s [%s] %s", + green, log.Type, reset, + platColor, log.Platform, reset, + log.Token, + log.Message, + ) case StatusFailedPush: - output = fmt.Sprintf("|%s %s %s| %s%s%s [%s] | %s | Error Message: %s", red, log.Type, reset, platColor, log.Platform, reset, log.Token, log.Message, log.Error) + output = fmt.Sprintf("|%s %s %s| %s%s%s [%s] | %s | Error Message: %s", + red, log.Type, reset, + platColor, log.Platform, reset, + log.Token, + log.Message, + log.Error, + ) } } diff --git a/gorush/server_test.go b/gorush/server_test.go index 1f69eab..f6fd780 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -200,7 +200,7 @@ func TestDisabledAndroidPushHandler(t *testing.T) { }) } -func TestAndroidPushHandler(t *testing.T) { +func TestHalfSuccessAndroidPushHandler(t *testing.T) { initTest() PushConf.Android.Enabled = true @@ -223,3 +223,30 @@ func TestAndroidPushHandler(t *testing.T) { assert.Equal(t, http.StatusOK, r.Code) }) } + +func TestAllSuccessAndroidPushHandler(t *testing.T) { + initTest() + + PushConf.Android.Enabled = true + PushConf.Android.ApiKey = os.Getenv("ANDROID_API_KEY") + // log for json + PushConf.Log.Format = "json" + + android_token := os.Getenv("ANDROID_TEST_TOKEN") + + r := gofight.New() + + r.POST("/api/push"). + SetJSON(gofight.D{ + "tokens": []string{android_token, android_token}, + "platform": 2, + "message": "Welcome", + }). + Run(GetMainEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { + + assert.Equal(t, http.StatusOK, r.Code) + }) + + // wait push response + time.Sleep(3000 * time.Millisecond) +}