Merge pull request #126 from appleboy/type

changed type for core section.
This commit is contained in:
Bo-Yi Wu 2016-09-02 16:02:56 +08:00 committed by GitHub
commit 38110adf56
7 changed files with 18 additions and 18 deletions

View File

@ -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"

View File

@ -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)

View File

@ -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()
}

View File

@ -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()
}
}

View File

@ -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"

View File

@ -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)

View File

@ -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()