From 74e83d87267bf772f0eef296fdf71d49f93d02ae Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 13 Apr 2016 15:22:04 +0800 Subject: [PATCH] rename to gorush Signed-off-by: Bo-Yi Wu --- .gitignore | 4 +-- .travis.yml | 2 +- Makefile | 18 +++++------ README.md | 30 +++++++++--------- doc.go | 10 +++--- docker/Dockerfile.build | 4 +-- docker/Dockerfile.dist | 4 +-- gorush.go | 62 ++++++++++++++++++------------------- gorush/config.go | 2 +- gorush/config_test.go | 2 +- gorush/const.go | 2 +- gorush/global.go | 2 +- gorush/log.go | 2 +- gorush/log_test.go | 2 +- gorush/notification.go | 2 +- gorush/notification_test.go | 2 +- gorush/server.go | 2 +- gorush/server_test.go | 8 ++--- gorush/version.go | 10 +++--- script/build.sh | 8 ++--- 20 files changed, 89 insertions(+), 89 deletions(-) diff --git a/.gitignore b/.gitignore index 8fb0034..56bf979 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,6 @@ config.yml bin/* .DS_Store coverage.out -gopush/log/*.log +gorush/log/*.log build.tar.gz -gopush.tar.gz +gorush.tar.gz diff --git a/.travis.yml b/.travis.yml index 491bf5e..90144e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ install: - go get github.com/mattn/goveralls script: - - cd gopush && go test -v -covermode=count -coverprofile=coverage.out + - cd gorush && go test -v -covermode=count -coverprofile=coverage.out - $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken=$COVERALLS_TOKEN diff --git a/Makefile b/Makefile index a29c724..32eeff4 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,9 @@ VERSION=0.0.1 DEPS := $(wildcard *.go) -BUILD_IMAGE := "gopush-build" -TEST_IMAGE := "gopush-testing" -PRODUCTION_IMAGE := "gopush" +BUILD_IMAGE := "gorush-build" +TEST_IMAGE := "gorush-testing" +PRODUCTION_IMAGE := "gorush" DEPLOY_ACCOUNT := "appleboy" all: build @@ -14,17 +14,17 @@ build: clean sh script/build.sh test: - cd gopush && go test -v -covermode=count -coverprofile=coverage.out + cd gorush && go test -v -covermode=count -coverprofile=coverage.out docker_build: clean - tar -zcvf build.tar.gz gopush.go gopush + tar -zcvf build.tar.gz gorush.go gorush docker build --rm -t $(BUILD_IMAGE) -f docker/Dockerfile.build . - docker run --rm $(BUILD_IMAGE) > gopush.tar.gz + docker run --rm $(BUILD_IMAGE) > gorush.tar.gz docker build --rm -t $(PRODUCTION_IMAGE) -f docker/Dockerfile.dist . docker_test: @docker build --rm -t $(TEST_IMAGE) -f docker/Dockerfile.testing . - @docker run --rm -e ANDROID_TEST_TOKEN=$(ANDROID_TEST_TOKEN) -e ANDROID_API_KEY=$(ANDROID_API_KEY) $(TEST_IMAGE) sh -c "cd gopush && go test -v" + @docker run --rm -e ANDROID_TEST_TOKEN=$(ANDROID_TEST_TOKEN) -e ANDROID_API_KEY=$(ANDROID_API_KEY) $(TEST_IMAGE) sh -c "cd gorush && go test -v" deploy: ifeq ($(tag),) @@ -35,7 +35,7 @@ endif docker push $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag) lint: - golint gopush + golint gorush clean: - -rm -rf build.tar.gz gopush.tar.gz bin/* + -rm -rf build.tar.gz gorush.tar.gz bin/* diff --git a/README.md b/README.md index 4954d5e..f122619 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Gopush +# gorush A push notification server using [Gin](https://github.com/gin-gonic/gin) framework written in Go (Golang). -[![GoDoc](https://godoc.org/github.com/appleboy/gopush?status.svg)](https://godoc.org/github.com/appleboy/gopush) [![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) +[![GoDoc](https://godoc.org/github.com/appleboy/gorush?status.svg)](https://godoc.org/github.com/appleboy/gorush) [![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/gorush/badge.svg?branch=master)](https://coveralls.io/github/appleboy/gorush?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/gorush)](https://goreportcard.com/report/github.com/appleboy/gorush) [![codebeat badge](https://codebeat.co/badges/ee01d852-b5e8-465a-ad93-631d738818ff)](https://codebeat.co/projects/github-com-appleboy-gorush) ## Support Platform @@ -54,18 +54,18 @@ log: ## Basic Usage -How to send push notification using `gopush` command? (Android or iOS) +How to send push notification using `gorush` command? (Android or iOS) ### Download a binary -The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/gopush/releases). +The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/gorush/releases). ### Send Android notification Send single notification with the following command. ```bash -$ gopush -android -m="your message" -k="API Key" -t="Device token" +$ gorush -android -m="your message" -k="API Key" -t="Device token" ``` * `-m`: Notification message. @@ -77,7 +77,7 @@ $ gopush -android -m="your message" -k="API Key" -t="Device token" Send single notification with the following command. ```bash -$ gopush -ios -m="your message" -i="API Key" -t="Device token" +$ gorush -ios -m="your message" -i="API Key" -t="Device token" ``` * `-m`: Notification message. @@ -87,15 +87,15 @@ $ gopush -ios -m="your message" -i="API Key" -t="Device token" The default endpoint is APNs development. Please add `-production` flag for APNs production push endpoint. ```bash -$ gopush -ios -m="your message" -i="API Key" -t="Device token" -production +$ gorush -ios -m="your message" -i="API Key" -t="Device token" -production ``` -## Run gopush web server +## Run gorush web server Please make sure your [config.yml](config/config.yml) exist. Default port is `8088`. ```bash -$ gopush -c config.yml +$ gorush -c config.yml ``` Test status of api server using [httpie](https://github.com/jkbrzt/httpie) tool: @@ -106,7 +106,7 @@ $ http -v --verify=no --json GET https://localhost:8088/api/status ## Web API -Gopush support the following API. +gorush support the following API. * **GET** `/api/status` Golang cpu, memory, gc, etc information. Thanks for [golang-stats-api-handler](https://github.com/fukata/golang-stats-api-handler). * **POST** `/api/push` push ios and android notifications. @@ -341,16 +341,16 @@ Success response: } ``` -## Run gopush in Docker +## Run gorush in Docker -Set up `gopush` in the cloud in under 5 minutes with zero knowledge of Golang or Linux shell using our [gopush Docker image](https://hub.docker.com/r/appleboy/gopush/). +Set up `gorush` in the cloud in under 5 minutes with zero knowledge of Golang or Linux shell using our [gorush Docker image](https://hub.docker.com/r/appleboy/gorush/). ```bash -$ docker pull appleboy/gopush -$ docker run -name gopush -p 80:8088 appleboy/gopush +$ docker pull appleboy/gorush +$ docker run -name gorush -p 80:8088 appleboy/gorush ``` -Testing your gopush server. +Testing your gorush server. ```bash $ http -v --verify=no --json GET http://your.docker.host/api/status diff --git a/doc.go b/doc.go index e48ae03..a3d6457 100644 --- a/doc.go +++ b/doc.go @@ -1,8 +1,8 @@ // A push notification server using Gin framework written in Go (Golang). // -// Details about the gopush project are found in github page: +// Details about the gorush project are found in github page: // -// https://github.com/appleboy/gopush +// https://github.com/appleboy/gorush // // Support Google Cloud Message using go-gcm library for Android. // Support HTTP/2 Apple Push Notification Service using apns2 library. @@ -16,15 +16,15 @@ // // Send Android notification // -// $ gopush -android -m="your message" -k="API Key" -t="Device token" +// $ gorush -android -m="your message" -k="API Key" -t="Device token" // // Send iOS notification // -// $ gopush -ios -m="your message" -i="API Key" -t="Device token" +// $ gorush -ios -m="your message" -i="API Key" -t="Device token" // // The default endpoint is APNs development. Please add -production flag for APNs production push endpoint. // -// $ gopush -ios -m="your message" -i="API Key" -t="Device token" -production +// $ gorush -ios -m="your message" -i="API Key" -t="Device token" -production // // For more details, see the documentation and example. // diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build index d70de57..1e3a942 100644 --- a/docker/Dockerfile.build +++ b/docker/Dockerfile.build @@ -7,6 +7,6 @@ RUN mkdir -p /tmp/build Add build.tar.gz /tmp/build/ WORKDIR /tmp/build RUN go get -v -d -RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w" -o bin/gopush gopush.go +RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w" -o bin/gorush gorush.go -CMD tar -C bin -czf - gopush +CMD tar -C bin -czf - gorush diff --git a/docker/Dockerfile.dist b/docker/Dockerfile.dist index 33e28d8..90c1e6a 100644 --- a/docker/Dockerfile.dist +++ b/docker/Dockerfile.dist @@ -7,8 +7,8 @@ RUN apk update && apk upgrade \ && rm -rf /var/cache/apk/* RUN mkdir /app -ADD gopush.tar.gz /app/ +ADD gorush.tar.gz /app/ ADD config /app/config WORKDIR /app -ENTRYPOINT ["./gopush", "-c", "config/config.yml"] +ENTRYPOINT ["./gorush", "-c", "config/config.yml"] EXPOSE 8088 diff --git a/gorush.go b/gorush.go index 2bb8c0c..a4ccaab 100644 --- a/gorush.go +++ b/gorush.go @@ -2,16 +2,16 @@ package main import ( "flag" - "github.com/appleboy/gopush/gopush" + "github.com/appleboy/gorush/gorush" "log" ) func main() { - version := flag.Bool("v", false, "gopush version") - confPath := flag.String("c", "", "yaml configuration file path for gopush") - certificateKeyPath := flag.String("i", "", "iOS certificate key file path for gopush") - apiKey := flag.String("k", "", "Android api key configuration for gopush") - port := flag.String("p", "", "port number for gopush") + version := flag.Bool("v", false, "gorush version") + confPath := flag.String("c", "", "yaml configuration file path for gorush") + certificateKeyPath := flag.String("i", "", "iOS certificate key file path for gorush") + apiKey := flag.String("k", "", "Android api key configuration for gorush") + port := flag.String("p", "", "port number for gorush") token := flag.String("t", "", "token string") message := flag.String("m", "", "notification message") android := flag.Bool("android", false, "send android notification") @@ -21,18 +21,18 @@ func main() { flag.Parse() if *version { - gopush.PrintGoPushVersion() + gorush.PrintGoRushVersion() return } var err error // set default parameters. - gopush.PushConf = gopush.BuildDefaultPushConf() + gorush.PushConf = gorush.BuildDefaultPushConf() // load user define config. if *confPath != "" { - gopush.PushConf, err = gopush.LoadConfYaml(*confPath) + gorush.PushConf, err = gorush.LoadConfYaml(*confPath) if err != nil { log.Printf("Load yaml config file error: '%v'", err) @@ -42,19 +42,19 @@ func main() { } if *certificateKeyPath != "" { - gopush.PushConf.Ios.PemKeyPath = *certificateKeyPath + gorush.PushConf.Ios.PemKeyPath = *certificateKeyPath } if *apiKey != "" { - gopush.PushConf.Android.APIKey = *apiKey + gorush.PushConf.Android.APIKey = *apiKey } // overwrite server port if *port != "" { - gopush.PushConf.Core.Port = *port + gorush.PushConf.Core.Port = *port } - if err = gopush.InitLog(); err != nil { + if err = gorush.InitLog(); err != nil { log.Println(err) return @@ -63,21 +63,21 @@ func main() { // send android notification if *android { if len(*token) == 0 { - gopush.LogError.Fatal("Missing token flag (-t)") + gorush.LogError.Fatal("Missing token flag (-t)") } if len(*message) == 0 { - gopush.LogError.Fatal("Missing message flag (-m)") + gorush.LogError.Fatal("Missing message flag (-m)") } - gopush.PushConf.Android.Enabled = true - req := gopush.PushNotification{ + gorush.PushConf.Android.Enabled = true + req := gorush.PushNotification{ Tokens: []string{*token}, - Platform: gopush.PlatFormAndroid, + Platform: gorush.PlatFormAndroid, Message: *message, } - gopush.PushToAndroid(req) + gorush.PushToAndroid(req) return } @@ -85,34 +85,34 @@ func main() { // send android notification if *ios { if len(*token) == 0 { - gopush.LogError.Fatal("Missing token flag (-t)") + gorush.LogError.Fatal("Missing token flag (-t)") } if len(*message) == 0 { - gopush.LogError.Fatal("Missing message flag (-m)") + gorush.LogError.Fatal("Missing message flag (-m)") } if *production { - gopush.PushConf.Ios.Production = true + gorush.PushConf.Ios.Production = true } - gopush.PushConf.Ios.Enabled = true - req := gopush.PushNotification{ + gorush.PushConf.Ios.Enabled = true + req := gorush.PushNotification{ Tokens: []string{*token}, - Platform: gopush.PlatFormIos, + Platform: gorush.PlatFormIos, Message: *message, } - gopush.InitAPNSClient() - gopush.PushToIOS(req) + gorush.InitAPNSClient() + gorush.PushToIOS(req) return } - if err = gopush.CheckPushConf(); err != nil { - gopush.LogError.Fatal(err) + if err = gorush.CheckPushConf(); err != nil { + gorush.LogError.Fatal(err) } - gopush.InitAPNSClient() - gopush.RunHTTPServer() + gorush.InitAPNSClient() + gorush.RunHTTPServer() } diff --git a/gorush/config.go b/gorush/config.go index 3fc5603..e78fd87 100644 --- a/gorush/config.go +++ b/gorush/config.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "gopkg.in/yaml.v2" diff --git a/gorush/config_test.go b/gorush/config_test.go index ef4e013..0888620 100644 --- a/gorush/config_test.go +++ b/gorush/config_test.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "github.com/stretchr/testify/assert" diff --git a/gorush/const.go b/gorush/const.go index a1663c6..81bb424 100644 --- a/gorush/const.go +++ b/gorush/const.go @@ -1,4 +1,4 @@ -package gopush +package gorush const ( // Version is gorush server version. diff --git a/gorush/global.go b/gorush/global.go index 5ee6c5b..1af3e26 100644 --- a/gorush/global.go +++ b/gorush/global.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "crypto/tls" diff --git a/gorush/log.go b/gorush/log.go index 5cc4c5e..42486f9 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "encoding/json" diff --git a/gorush/log_test.go b/gorush/log_test.go index 1229a26..b5cdbcc 100644 --- a/gorush/log_test.go +++ b/gorush/log_test.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "github.com/Sirupsen/logrus" diff --git a/gorush/notification.go b/gorush/notification.go index 5ca3aba..3a9ee9d 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "errors" diff --git a/gorush/notification_test.go b/gorush/notification_test.go index f686540..fe199ce 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "encoding/json" diff --git a/gorush/server.go b/gorush/server.go index 840cf64..d6eba77 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "fmt" diff --git a/gorush/server_test.go b/gorush/server_test.go index df2b6ce..8855683 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "github.com/appleboy/gofight" @@ -19,8 +19,8 @@ func initTest() { PushConf.Core.Mode = "test" } -func TestPrintGoPushVersion(t *testing.T) { - PrintGoPushVersion() +func TestPrintGoRushVersion(t *testing.T) { + PrintGoRushVersion() } func TestRunNormalServer(t *testing.T) { @@ -85,7 +85,7 @@ func TestAPIStatusHandler(t *testing.T) { Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { data := []byte(r.Body.String()) - value, _ := jsonparser.GetString(data, "goVersion") + value, _ := jsonparser.GetString(data, "go_version") assert.Equal(t, goVersion, value) assert.Equal(t, http.StatusOK, r.Code) diff --git a/gorush/version.go b/gorush/version.go index bd54b24..cbc4ea7 100644 --- a/gorush/version.go +++ b/gorush/version.go @@ -1,4 +1,4 @@ -package gopush +package gorush import ( "fmt" @@ -6,9 +6,9 @@ import ( "runtime" ) -// PrintGoPushVersion provide print server engine -func PrintGoPushVersion() { - fmt.Printf(`GoPush %s, Compiler: %s %s, Copyright (C) 2016 Bo-Yi Wu, Inc.`, +// PrintGoRushVersion provide print server engine +func PrintGoRushVersion() { + fmt.Printf(`GoRush %s, Compiler: %s %s, Copyright (C) 2016 Bo-Yi Wu, Inc.`, Version, runtime.Compiler, runtime.Version()) @@ -18,7 +18,7 @@ func PrintGoPushVersion() { func VersionMiddleware() gin.HandlerFunc { // Set out header value for each response return func(c *gin.Context) { - c.Writer.Header().Set("Server-Version", "GoPush/"+Version) + c.Writer.Header().Set("Server-Version", "GoRush/"+Version) c.Next() } } diff --git a/script/build.sh b/script/build.sh index 324ed90..dc6dea0 100755 --- a/script/build.sh +++ b/script/build.sh @@ -5,11 +5,11 @@ ARCH="amd64" for GOOS in $OS; do for GOARCH in $ARCH; do - EXE="gopush" - (test "$GOOS" = "windows") && EXE="gopush.exe" + EXE="gorush" + (test "$GOOS" = "windows") && EXE="gorush.exe" echo "Build: ${GOOS}, Arch: ${GOARCH}, EXE: ${EXE}" - GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-w" -o bin/$GOOS/$GOARCH/${EXE} gopush.go; - tar -C bin/$GOOS/$GOARCH -czf bin/gopush-$GOOS-$GOARCH.tar.gz gopush + GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-w" -o bin/$GOOS/$GOARCH/${EXE} gorush.go; + tar -C bin/$GOOS/$GOARCH -czf bin/gorush-$GOOS-$GOARCH.tar.gz gorush done done