feat(config): add grpc config. (#255)

This commit is contained in:
Bo-Yi Wu
2017-07-24 18:58:30 +08:00
committed by GitHub
parent 9a52f8f2b5
commit 41a8a609be
6 changed files with 35 additions and 3 deletions

View File

@@ -45,7 +45,12 @@ func (s *server) Send(ctx context.Context, in *pb.NotificationRequest) (*pb.Noti
// RunGRPCServer run gorush grpc server
func RunGRPCServer() error {
lis, err := net.Listen("tcp", port)
if !gorush.PushConf.GRPC.Enabled {
gorush.LogAccess.Debug("gRPC server is disabled.")
return nil
}
lis, err := net.Listen("tcp", ":"+gorush.PushConf.GRPC.Port)
if err != nil {
gorush.LogError.Error("failed to listen: %v", err)
return err
@@ -54,6 +59,7 @@ func RunGRPCServer() error {
pb.RegisterGorushServer(s, &server{})
// Register reflection service on gRPC server.
reflection.Register(s)
gorush.LogAccess.Debug("gRPC server is running on " + gorush.PushConf.GRPC.Port + " port.")
if err := s.Serve(lis); err != nil {
gorush.LogError.Error("failed to serve: %v", err)
return err