rename to gorush

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-13 15:22:04 +08:00
parent ceab65f733
commit 74e83d8726
20 changed files with 89 additions and 89 deletions

4
.gitignore vendored
View File

@ -29,6 +29,6 @@ config.yml
bin/* bin/*
.DS_Store .DS_Store
coverage.out coverage.out
gopush/log/*.log gorush/log/*.log
build.tar.gz build.tar.gz
gopush.tar.gz gorush.tar.gz

View File

@ -24,7 +24,7 @@ install:
- go get github.com/mattn/goveralls - go get github.com/mattn/goveralls
script: 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 - $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls -coverprofile=coverage.out
-service=travis-ci -repotoken=$COVERALLS_TOKEN -service=travis-ci -repotoken=$COVERALLS_TOKEN

View File

@ -3,9 +3,9 @@
VERSION=0.0.1 VERSION=0.0.1
DEPS := $(wildcard *.go) DEPS := $(wildcard *.go)
BUILD_IMAGE := "gopush-build" BUILD_IMAGE := "gorush-build"
TEST_IMAGE := "gopush-testing" TEST_IMAGE := "gorush-testing"
PRODUCTION_IMAGE := "gopush" PRODUCTION_IMAGE := "gorush"
DEPLOY_ACCOUNT := "appleboy" DEPLOY_ACCOUNT := "appleboy"
all: build all: build
@ -14,17 +14,17 @@ build: clean
sh script/build.sh sh script/build.sh
test: test:
cd gopush && go test -v -covermode=count -coverprofile=coverage.out cd gorush && go test -v -covermode=count -coverprofile=coverage.out
docker_build: clean 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 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 build --rm -t $(PRODUCTION_IMAGE) -f docker/Dockerfile.dist .
docker_test: docker_test:
@docker build --rm -t $(TEST_IMAGE) -f docker/Dockerfile.testing . @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: deploy:
ifeq ($(tag),) ifeq ($(tag),)
@ -35,7 +35,7 @@ endif
docker push $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag) docker push $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag)
lint: lint:
golint gopush golint gorush
clean: clean:
-rm -rf build.tar.gz gopush.tar.gz bin/* -rm -rf build.tar.gz gorush.tar.gz bin/*

View File

@ -1,8 +1,8 @@
# Gopush # gorush
A push notification server using [Gin](https://github.com/gin-gonic/gin) framework written in Go (Golang). 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 ## Support Platform
@ -54,18 +54,18 @@ log:
## Basic Usage ## 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 ### 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 Android notification
Send single notification with the following command. Send single notification with the following command.
```bash ```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. * `-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. Send single notification with the following command.
```bash ```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. * `-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. The default endpoint is APNs development. Please add `-production` flag for APNs production push endpoint.
```bash ```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`. Please make sure your [config.yml](config/config.yml) exist. Default port is `8088`.
```bash ```bash
$ gopush -c config.yml $ gorush -c config.yml
``` ```
Test status of api server using [httpie](https://github.com/jkbrzt/httpie) tool: 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 ## 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). * **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. * **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 ```bash
$ docker pull appleboy/gopush $ docker pull appleboy/gorush
$ docker run -name gopush -p 80:8088 appleboy/gopush $ docker run -name gorush -p 80:8088 appleboy/gorush
``` ```
Testing your gopush server. Testing your gorush server.
```bash ```bash
$ http -v --verify=no --json GET http://your.docker.host/api/status $ http -v --verify=no --json GET http://your.docker.host/api/status

10
doc.go
View File

@ -1,8 +1,8 @@
// A push notification server using Gin framework written in Go (Golang). // 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 Google Cloud Message using go-gcm library for Android.
// Support HTTP/2 Apple Push Notification Service using apns2 library. // Support HTTP/2 Apple Push Notification Service using apns2 library.
@ -16,15 +16,15 @@
// //
// Send Android notification // 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 // 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. // 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. // For more details, see the documentation and example.
// //

View File

@ -7,6 +7,6 @@ RUN mkdir -p /tmp/build
Add build.tar.gz /tmp/build/ Add build.tar.gz /tmp/build/
WORKDIR /tmp/build WORKDIR /tmp/build
RUN go get -v -d 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

View File

@ -7,8 +7,8 @@ RUN apk update && apk upgrade \
&& rm -rf /var/cache/apk/* && rm -rf /var/cache/apk/*
RUN mkdir /app RUN mkdir /app
ADD gopush.tar.gz /app/ ADD gorush.tar.gz /app/
ADD config /app/config ADD config /app/config
WORKDIR /app WORKDIR /app
ENTRYPOINT ["./gopush", "-c", "config/config.yml"] ENTRYPOINT ["./gorush", "-c", "config/config.yml"]
EXPOSE 8088 EXPOSE 8088

View File

@ -2,16 +2,16 @@ package main
import ( import (
"flag" "flag"
"github.com/appleboy/gopush/gopush" "github.com/appleboy/gorush/gorush"
"log" "log"
) )
func main() { func main() {
version := flag.Bool("v", false, "gopush version") version := flag.Bool("v", false, "gorush version")
confPath := flag.String("c", "", "yaml configuration file path for gopush") confPath := flag.String("c", "", "yaml configuration file path for gorush")
certificateKeyPath := flag.String("i", "", "iOS certificate key file path for gopush") certificateKeyPath := flag.String("i", "", "iOS certificate key file path for gorush")
apiKey := flag.String("k", "", "Android api key configuration for gopush") apiKey := flag.String("k", "", "Android api key configuration for gorush")
port := flag.String("p", "", "port number for gopush") port := flag.String("p", "", "port number for gorush")
token := flag.String("t", "", "token string") token := flag.String("t", "", "token string")
message := flag.String("m", "", "notification message") message := flag.String("m", "", "notification message")
android := flag.Bool("android", false, "send android notification") android := flag.Bool("android", false, "send android notification")
@ -21,18 +21,18 @@ func main() {
flag.Parse() flag.Parse()
if *version { if *version {
gopush.PrintGoPushVersion() gorush.PrintGoRushVersion()
return return
} }
var err error var err error
// set default parameters. // set default parameters.
gopush.PushConf = gopush.BuildDefaultPushConf() gorush.PushConf = gorush.BuildDefaultPushConf()
// load user define config. // load user define config.
if *confPath != "" { if *confPath != "" {
gopush.PushConf, err = gopush.LoadConfYaml(*confPath) gorush.PushConf, err = gorush.LoadConfYaml(*confPath)
if err != nil { if err != nil {
log.Printf("Load yaml config file error: '%v'", err) log.Printf("Load yaml config file error: '%v'", err)
@ -42,19 +42,19 @@ func main() {
} }
if *certificateKeyPath != "" { if *certificateKeyPath != "" {
gopush.PushConf.Ios.PemKeyPath = *certificateKeyPath gorush.PushConf.Ios.PemKeyPath = *certificateKeyPath
} }
if *apiKey != "" { if *apiKey != "" {
gopush.PushConf.Android.APIKey = *apiKey gorush.PushConf.Android.APIKey = *apiKey
} }
// overwrite server port // overwrite server port
if *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) log.Println(err)
return return
@ -63,21 +63,21 @@ func main() {
// send android notification // send android notification
if *android { if *android {
if len(*token) == 0 { if len(*token) == 0 {
gopush.LogError.Fatal("Missing token flag (-t)") gorush.LogError.Fatal("Missing token flag (-t)")
} }
if len(*message) == 0 { if len(*message) == 0 {
gopush.LogError.Fatal("Missing message flag (-m)") gorush.LogError.Fatal("Missing message flag (-m)")
} }
gopush.PushConf.Android.Enabled = true gorush.PushConf.Android.Enabled = true
req := gopush.PushNotification{ req := gorush.PushNotification{
Tokens: []string{*token}, Tokens: []string{*token},
Platform: gopush.PlatFormAndroid, Platform: gorush.PlatFormAndroid,
Message: *message, Message: *message,
} }
gopush.PushToAndroid(req) gorush.PushToAndroid(req)
return return
} }
@ -85,34 +85,34 @@ func main() {
// send android notification // send android notification
if *ios { if *ios {
if len(*token) == 0 { if len(*token) == 0 {
gopush.LogError.Fatal("Missing token flag (-t)") gorush.LogError.Fatal("Missing token flag (-t)")
} }
if len(*message) == 0 { if len(*message) == 0 {
gopush.LogError.Fatal("Missing message flag (-m)") gorush.LogError.Fatal("Missing message flag (-m)")
} }
if *production { if *production {
gopush.PushConf.Ios.Production = true gorush.PushConf.Ios.Production = true
} }
gopush.PushConf.Ios.Enabled = true gorush.PushConf.Ios.Enabled = true
req := gopush.PushNotification{ req := gorush.PushNotification{
Tokens: []string{*token}, Tokens: []string{*token},
Platform: gopush.PlatFormIos, Platform: gorush.PlatFormIos,
Message: *message, Message: *message,
} }
gopush.InitAPNSClient() gorush.InitAPNSClient()
gopush.PushToIOS(req) gorush.PushToIOS(req)
return return
} }
if err = gopush.CheckPushConf(); err != nil { if err = gorush.CheckPushConf(); err != nil {
gopush.LogError.Fatal(err) gorush.LogError.Fatal(err)
} }
gopush.InitAPNSClient() gorush.InitAPNSClient()
gopush.RunHTTPServer() gorush.RunHTTPServer()
} }

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"

View File

@ -1,4 +1,4 @@
package gopush package gorush
const ( const (
// Version is gorush server version. // Version is gorush server version.

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"crypto/tls" "crypto/tls"

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"errors" "errors"

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"github.com/appleboy/gofight" "github.com/appleboy/gofight"
@ -19,8 +19,8 @@ func initTest() {
PushConf.Core.Mode = "test" PushConf.Core.Mode = "test"
} }
func TestPrintGoPushVersion(t *testing.T) { func TestPrintGoRushVersion(t *testing.T) {
PrintGoPushVersion() PrintGoRushVersion()
} }
func TestRunNormalServer(t *testing.T) { func TestRunNormalServer(t *testing.T) {
@ -85,7 +85,7 @@ func TestAPIStatusHandler(t *testing.T) {
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
data := []byte(r.Body.String()) data := []byte(r.Body.String())
value, _ := jsonparser.GetString(data, "goVersion") value, _ := jsonparser.GetString(data, "go_version")
assert.Equal(t, goVersion, value) assert.Equal(t, goVersion, value)
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)

View File

@ -1,4 +1,4 @@
package gopush package gorush
import ( import (
"fmt" "fmt"
@ -6,9 +6,9 @@ import (
"runtime" "runtime"
) )
// PrintGoPushVersion provide print server engine // PrintGoRushVersion provide print server engine
func PrintGoPushVersion() { func PrintGoRushVersion() {
fmt.Printf(`GoPush %s, Compiler: %s %s, Copyright (C) 2016 Bo-Yi Wu, Inc.`, fmt.Printf(`GoRush %s, Compiler: %s %s, Copyright (C) 2016 Bo-Yi Wu, Inc.`,
Version, Version,
runtime.Compiler, runtime.Compiler,
runtime.Version()) runtime.Version())
@ -18,7 +18,7 @@ func PrintGoPushVersion() {
func VersionMiddleware() gin.HandlerFunc { func VersionMiddleware() gin.HandlerFunc {
// Set out header value for each response // Set out header value for each response
return func(c *gin.Context) { return func(c *gin.Context) {
c.Writer.Header().Set("Server-Version", "GoPush/"+Version) c.Writer.Header().Set("Server-Version", "GoRush/"+Version)
c.Next() c.Next()
} }
} }

View File

@ -5,11 +5,11 @@ ARCH="amd64"
for GOOS in $OS; do for GOOS in $OS; do
for GOARCH in $ARCH; do for GOARCH in $ARCH; do
EXE="gopush" EXE="gorush"
(test "$GOOS" = "windows") && EXE="gopush.exe" (test "$GOOS" = "windows") && EXE="gorush.exe"
echo "Build: ${GOOS}, Arch: ${GOARCH}, EXE: ${EXE}" echo "Build: ${GOOS}, Arch: ${GOARCH}, EXE: ${EXE}"
GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-w" -o bin/$GOOS/$GOARCH/${EXE} gopush.go; GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-w" -o bin/$GOOS/$GOARCH/${EXE} gorush.go;
tar -C bin/$GOOS/$GOARCH -czf bin/gopush-$GOOS-$GOARCH.tar.gz gopush tar -C bin/$GOOS/$GOARCH -czf bin/gorush-$GOOS-$GOARCH.tar.gz gorush
done done
done done