Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add grpc config. #255

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ core:
folder: ".cache" # folder for storing TLS certificates
host: "" # which domains the Let's Encrypt will attempt

grpc:
enabled: false
port: 50051

api:
push_uri: "/api/push"
stat_go_uri: "/api/stat/go"
Expand Down
13 changes: 11 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ConfYaml struct {
Ios SectionIos `yaml:"ios"`
Log SectionLog `yaml:"log"`
Stat SectionStat `yaml:"stat"`
GRPC SectionGRPC `yaml:"grpc"`
}

// SectionCore is sub section of config.
Expand Down Expand Up @@ -115,6 +116,12 @@ type SectionPID struct {
Override bool `yaml:"override"`
}

// SectionGRPC is sub section of config.
type SectionGRPC struct {
Enabled bool `yaml:"enabled"`
Port string `yaml:"port"`
}

// BuildDefaultPushConf is default config setting.
func BuildDefaultPushConf() ConfYaml {
var conf ConfYaml
Expand Down Expand Up @@ -165,17 +172,19 @@ func BuildDefaultPushConf() ConfYaml {
conf.Log.ErrorLevel = "error"
conf.Log.HideToken = true

// Stat Engine
conf.Stat.Engine = "memory"
conf.Stat.Redis.Addr = "localhost:6379"
conf.Stat.Redis.Password = ""
conf.Stat.Redis.DB = 0

conf.Stat.BoltDB.Path = "bolt.db"
conf.Stat.BoltDB.Bucket = "gorush"

conf.Stat.BuntDB.Path = "bunt.db"
conf.Stat.LevelDB.Path = "level.db"

// gRPC Server
conf.GRPC.Enabled = false
conf.GRPC.Port = "50051"
return conf
}

Expand Down
4 changes: 4 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ core:
folder: ".cache" # folder for storing TLS certificates
host: "" # which domains the Let's Encrypt will attempt

grpc:
enabled: false
port: 50051

api:
push_uri: "/api/push"
stat_go_uri: "/api/stat/go"
Expand Down
8 changes: 8 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {

assert.Equal(suite.T(), "bunt.db", suite.ConfGorushDefault.Stat.BuntDB.Path)
assert.Equal(suite.T(), "level.db", suite.ConfGorushDefault.Stat.LevelDB.Path)

// gRPC
assert.Equal(suite.T(), false, suite.ConfGorushDefault.GRPC.Enabled)
assert.Equal(suite.T(), "50051", suite.ConfGorushDefault.GRPC.Port)
}

func (suite *ConfigTestSuite) TestValidateConf() {
Expand Down Expand Up @@ -171,6 +175,10 @@ func (suite *ConfigTestSuite) TestValidateConf() {

assert.Equal(suite.T(), "bunt.db", suite.ConfGorush.Stat.BuntDB.Path)
assert.Equal(suite.T(), "level.db", suite.ConfGorush.Stat.LevelDB.Path)

// gRPC
assert.Equal(suite.T(), false, suite.ConfGorush.GRPC.Enabled)
assert.Equal(suite.T(), "50051", suite.ConfGorush.GRPC.Port)
}

func TestConfigTestSuite(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions gorush/server_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

// RunHTTPServer provide run http or https protocol.
func RunHTTPServer() (err error) {
LogAccess.Debug("HTTPD server is running on " + PushConf.Core.Port + " port.")
if PushConf.Core.AutoTLS.Enabled {
err = gracehttp.Serve(autoTLSServer())
} else if PushConf.Core.SSL && PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" {
Expand Down
8 changes: 7 additions & 1 deletion rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down