From 3294dbaf952e33333436729a7ba1c4bb55050b9b Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 2 Sep 2016 15:55:47 +0800 Subject: [PATCH] changed type for core section. Signed-off-by: Bo-Yi Wu --- config/config.go | 12 ++++++------ config/config_test.go | 12 ++++++------ gorush.go | 2 +- gorush/notification.go | 4 ++-- gorush/notification_test.go | 2 +- gorush/server.go | 2 +- gorush/server_test.go | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/config/config.go b/config/config.go index db1b883..104bed3 100644 --- a/config/config.go +++ b/config/config.go @@ -19,9 +19,9 @@ type ConfYaml struct { // SectionCore is sub seciont of config. type SectionCore struct { Port string `yaml:"port"` - MaxNotification int `yaml:"max_notification"` - WorkerNum int `yaml:"worker_num"` - QueueNum int `yaml:"queue_num"` + MaxNotification int64 `yaml:"max_notification"` + WorkerNum int64 `yaml:"worker_num"` + QueueNum int64 `yaml:"queue_num"` Mode string `yaml:"mode"` SSL bool `yaml:"ssl"` CertPath string `yaml:"cert_path"` @@ -102,13 +102,13 @@ func BuildDefaultPushConf() ConfYaml { // Core conf.Core.Port = "8088" - conf.Core.WorkerNum = runtime.NumCPU() - conf.Core.QueueNum = 8192 + conf.Core.WorkerNum = int64(runtime.NumCPU()) + conf.Core.QueueNum = int64(8192) conf.Core.Mode = "release" conf.Core.SSL = false conf.Core.CertPath = "cert.pem" conf.Core.KeyPath = "key.pem" - conf.Core.MaxNotification = 100 + conf.Core.MaxNotification = int64(100) conf.Core.HTTPProxy = "" conf.Core.PID.Enabled = false conf.Core.PID.Path = "gorush.pid" diff --git a/config/config_test.go b/config/config_test.go index fb59ddb..c22e674 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -55,13 +55,13 @@ func (suite *ConfigTestSuite) SetupTest() { func (suite *ConfigTestSuite) TestValidateConfDefault() { // Core assert.Equal(suite.T(), "8088", suite.ConfGorushDefault.Core.Port) - assert.Equal(suite.T(), runtime.NumCPU(), suite.ConfGorushDefault.Core.WorkerNum) - assert.Equal(suite.T(), 8192, suite.ConfGorushDefault.Core.QueueNum) + assert.Equal(suite.T(), int64(runtime.NumCPU()), suite.ConfGorushDefault.Core.WorkerNum) + assert.Equal(suite.T(), int64(8192), suite.ConfGorushDefault.Core.QueueNum) assert.Equal(suite.T(), "release", suite.ConfGorushDefault.Core.Mode) assert.Equal(suite.T(), false, suite.ConfGorushDefault.Core.SSL) assert.Equal(suite.T(), "cert.pem", suite.ConfGorushDefault.Core.CertPath) assert.Equal(suite.T(), "key.pem", suite.ConfGorushDefault.Core.KeyPath) - assert.Equal(suite.T(), 100, suite.ConfGorushDefault.Core.MaxNotification) + assert.Equal(suite.T(), int64(100), suite.ConfGorushDefault.Core.MaxNotification) assert.Equal(suite.T(), "", suite.ConfGorushDefault.Core.HTTPProxy) // Pid assert.Equal(suite.T(), false, suite.ConfGorushDefault.Core.PID.Enabled) @@ -107,13 +107,13 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() { func (suite *ConfigTestSuite) TestValidateConf() { // Core assert.Equal(suite.T(), "8088", suite.ConfGorush.Core.Port) - assert.Equal(suite.T(), 8, suite.ConfGorush.Core.WorkerNum) - assert.Equal(suite.T(), 8192, suite.ConfGorush.Core.QueueNum) + assert.Equal(suite.T(), int64(8), suite.ConfGorush.Core.WorkerNum) + assert.Equal(suite.T(), int64(8192), suite.ConfGorush.Core.QueueNum) assert.Equal(suite.T(), "release", suite.ConfGorush.Core.Mode) assert.Equal(suite.T(), false, suite.ConfGorush.Core.SSL) assert.Equal(suite.T(), "cert.pem", suite.ConfGorush.Core.CertPath) assert.Equal(suite.T(), "key.pem", suite.ConfGorush.Core.KeyPath) - assert.Equal(suite.T(), 100, suite.ConfGorush.Core.MaxNotification) + assert.Equal(suite.T(), int64(100), suite.ConfGorush.Core.MaxNotification) assert.Equal(suite.T(), "", suite.ConfGorush.Core.HTTPProxy) // Pid assert.Equal(suite.T(), false, suite.ConfGorush.Core.PID.Enabled) diff --git a/gorush.go b/gorush.go index 841c22b..f7c8d7b 100644 --- a/gorush.go +++ b/gorush.go @@ -236,6 +236,6 @@ func main() { gorush.InitAppStatus() gorush.InitAPNSClient() - gorush.InitWorkers(gorush.PushConf.Core.WorkerNum, gorush.PushConf.Core.QueueNum) + gorush.InitWorkers(int64(gorush.PushConf.Core.WorkerNum), int64(gorush.PushConf.Core.QueueNum)) gorush.RunHTTPServer() } diff --git a/gorush/notification.go b/gorush/notification.go index 078a1d9..d7d75f2 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -186,10 +186,10 @@ func InitAPNSClient() error { } // InitWorkers for initialize all workers. -func InitWorkers(workerNum, queueNum int) { +func InitWorkers(workerNum int64, queueNum int64) { LogAccess.Debug("worker number is ", workerNum, ", queue number is ", queueNum) QueueNotification = make(chan PushNotification, queueNum) - for i := 0; i < workerNum; i++ { + for i := int64(0); i < workerNum; i++ { go startWorker() } } diff --git a/gorush/notification_test.go b/gorush/notification_test.go index 71f23e8..5f8f1de 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -329,7 +329,7 @@ func TestOverwriteAndroidAPIKey(t *testing.T) { func TestSenMultipleNotifications(t *testing.T) { PushConf = config.BuildDefaultPushConf() - InitWorkers(2, 2) + InitWorkers(int64(2), 2) PushConf.Ios.Enabled = true PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem" diff --git a/gorush/server.go b/gorush/server.go index 0f7318e..892a404 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -40,7 +40,7 @@ func pushHandler(c *gin.Context) { return } - if len(form.Notifications) > PushConf.Core.MaxNotification { + if int64(len(form.Notifications)) > PushConf.Core.MaxNotification { msg = fmt.Sprintf("Number of notifications(%d) over limit(%d)", len(form.Notifications), PushConf.Core.MaxNotification) LogAccess.Debug(msg) abortWithError(c, http.StatusBadRequest, msg) diff --git a/gorush/server_test.go b/gorush/server_test.go index 2555e1b..7e88f67 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -151,7 +151,7 @@ func TestEmptyNotifications(t *testing.T) { func TestOutOfRangeMaxNotifications(t *testing.T) { initTest() - PushConf.Core.MaxNotification = 1 + PushConf.Core.MaxNotification = int64(1) r := gofight.New()