Skip to content

Commit

Permalink
feat(grpc): initial grpc server. (#253)
Browse files Browse the repository at this point in the history
* feat(grpc): initial grpc server.

* refactor(vendor): add missing vendor.

* fix testing

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy authored Jul 24, 2017
1 parent 478e39e commit 9a52f8f
Show file tree
Hide file tree
Showing 102 changed files with 21,797 additions and 442 deletions.
2 changes: 1 addition & 1 deletion gorush/notification_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ Retry:
goto Retry
}

return true
return !isError
}
6 changes: 3 additions & 3 deletions gorush/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func TestPushToAndroidWrongToken(t *testing.T) {
}

success := PushToAndroid(req)
assert.True(t, success)
assert.False(t, success)
}

func TestPushToAndroidRightTokenForJSONLog(t *testing.T) {
Expand All @@ -489,7 +489,7 @@ func TestPushToAndroidRightTokenForJSONLog(t *testing.T) {
androidToken := os.Getenv("ANDROID_TEST_TOKEN")

req := PushNotification{
Tokens: []string{androidToken, "bbbbb"},
Tokens: []string{androidToken},
Platform: PlatFormAndroid,
Message: "Welcome",
}
Expand All @@ -513,7 +513,7 @@ func TestPushToAndroidRightTokenForStringLog(t *testing.T) {
}

success := PushToAndroid(req)
assert.True(t, success)
assert.False(t, success)
}

func TestOverwriteAndroidAPIKey(t *testing.T) {
Expand Down
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package main
import (
"flag"
"fmt"
"golang.org/x/sync/errgroup"
"log"
"os"
"path/filepath"
"strconv"

"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/rpc"
)

func checkInput(token, message string) {
Expand Down Expand Up @@ -294,7 +296,18 @@ func main() {

gorush.InitWorkers(gorush.PushConf.Core.WorkerNum, gorush.PushConf.Core.QueueNum)

if err = gorush.RunHTTPServer(); err != nil {
var g errgroup.Group

g.Go(func() error {
// Run httpd server
return gorush.RunHTTPServer()
})
g.Go(func() error {
// Run gRPC internal server
return rpc.RunGRPCServer()
})

if err = g.Wait(); err != nil {
gorush.LogError.Fatal(err)
}
}
35 changes: 35 additions & 0 deletions rpc/example/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"log"

pb "github.com/appleboy/gorush/rpc/proto"
"golang.org/x/net/context"
"google.golang.org/grpc"
)

const (
address = "localhost:50051"
defaultName = "world"
)

func main() {
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewGorushClient(conn)

r, err := c.Send(context.Background(), &pb.NotificationRequest{
Platform: 2,
Tokens: []string{"1234567890"},
Message: "test message",
})
if err != nil {
log.Fatalf("could not greet: %v", err)
}
log.Printf("Success: %t\n", r.Success)
log.Printf("Count: %d\n", r.Counts)
}
212 changes: 212 additions & 0 deletions rpc/proto/gorush.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions rpc/proto/gorush.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package proto;

message NotificationRequest {
repeated string tokens = 1;
int32 platform = 2;
string message = 3;
string title = 4;
string topic = 5;
string key = 6;
}

message NotificationReply {
bool success = 1;
int32 counts = 2;
}

service Gorush {
rpc Send (NotificationRequest) returns (NotificationReply) {}
}

Loading

0 comments on commit 9a52f8f

Please sign in to comment.