Merge pull request #126 from appleboy/type
changed type for core section.
This commit is contained in:
commit
38110adf56
|
@ -19,9 +19,9 @@ type ConfYaml struct {
|
||||||
// SectionCore is sub seciont of config.
|
// SectionCore is sub seciont of config.
|
||||||
type SectionCore struct {
|
type SectionCore struct {
|
||||||
Port string `yaml:"port"`
|
Port string `yaml:"port"`
|
||||||
MaxNotification int `yaml:"max_notification"`
|
MaxNotification int64 `yaml:"max_notification"`
|
||||||
WorkerNum int `yaml:"worker_num"`
|
WorkerNum int64 `yaml:"worker_num"`
|
||||||
QueueNum int `yaml:"queue_num"`
|
QueueNum int64 `yaml:"queue_num"`
|
||||||
Mode string `yaml:"mode"`
|
Mode string `yaml:"mode"`
|
||||||
SSL bool `yaml:"ssl"`
|
SSL bool `yaml:"ssl"`
|
||||||
CertPath string `yaml:"cert_path"`
|
CertPath string `yaml:"cert_path"`
|
||||||
|
@ -102,13 +102,13 @@ func BuildDefaultPushConf() ConfYaml {
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
conf.Core.Port = "8088"
|
conf.Core.Port = "8088"
|
||||||
conf.Core.WorkerNum = runtime.NumCPU()
|
conf.Core.WorkerNum = int64(runtime.NumCPU())
|
||||||
conf.Core.QueueNum = 8192
|
conf.Core.QueueNum = int64(8192)
|
||||||
conf.Core.Mode = "release"
|
conf.Core.Mode = "release"
|
||||||
conf.Core.SSL = false
|
conf.Core.SSL = false
|
||||||
conf.Core.CertPath = "cert.pem"
|
conf.Core.CertPath = "cert.pem"
|
||||||
conf.Core.KeyPath = "key.pem"
|
conf.Core.KeyPath = "key.pem"
|
||||||
conf.Core.MaxNotification = 100
|
conf.Core.MaxNotification = int64(100)
|
||||||
conf.Core.HTTPProxy = ""
|
conf.Core.HTTPProxy = ""
|
||||||
conf.Core.PID.Enabled = false
|
conf.Core.PID.Enabled = false
|
||||||
conf.Core.PID.Path = "gorush.pid"
|
conf.Core.PID.Path = "gorush.pid"
|
||||||
|
|
|
@ -55,13 +55,13 @@ func (suite *ConfigTestSuite) SetupTest() {
|
||||||
func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
||||||
// Core
|
// Core
|
||||||
assert.Equal(suite.T(), "8088", suite.ConfGorushDefault.Core.Port)
|
assert.Equal(suite.T(), "8088", suite.ConfGorushDefault.Core.Port)
|
||||||
assert.Equal(suite.T(), runtime.NumCPU(), suite.ConfGorushDefault.Core.WorkerNum)
|
assert.Equal(suite.T(), int64(runtime.NumCPU()), suite.ConfGorushDefault.Core.WorkerNum)
|
||||||
assert.Equal(suite.T(), 8192, suite.ConfGorushDefault.Core.QueueNum)
|
assert.Equal(suite.T(), int64(8192), suite.ConfGorushDefault.Core.QueueNum)
|
||||||
assert.Equal(suite.T(), "release", suite.ConfGorushDefault.Core.Mode)
|
assert.Equal(suite.T(), "release", suite.ConfGorushDefault.Core.Mode)
|
||||||
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Core.SSL)
|
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Core.SSL)
|
||||||
assert.Equal(suite.T(), "cert.pem", suite.ConfGorushDefault.Core.CertPath)
|
assert.Equal(suite.T(), "cert.pem", suite.ConfGorushDefault.Core.CertPath)
|
||||||
assert.Equal(suite.T(), "key.pem", suite.ConfGorushDefault.Core.KeyPath)
|
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)
|
assert.Equal(suite.T(), "", suite.ConfGorushDefault.Core.HTTPProxy)
|
||||||
// Pid
|
// Pid
|
||||||
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Core.PID.Enabled)
|
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Core.PID.Enabled)
|
||||||
|
@ -107,13 +107,13 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
||||||
func (suite *ConfigTestSuite) TestValidateConf() {
|
func (suite *ConfigTestSuite) TestValidateConf() {
|
||||||
// Core
|
// Core
|
||||||
assert.Equal(suite.T(), "8088", suite.ConfGorush.Core.Port)
|
assert.Equal(suite.T(), "8088", suite.ConfGorush.Core.Port)
|
||||||
assert.Equal(suite.T(), 8, suite.ConfGorush.Core.WorkerNum)
|
assert.Equal(suite.T(), int64(8), suite.ConfGorush.Core.WorkerNum)
|
||||||
assert.Equal(suite.T(), 8192, suite.ConfGorush.Core.QueueNum)
|
assert.Equal(suite.T(), int64(8192), suite.ConfGorush.Core.QueueNum)
|
||||||
assert.Equal(suite.T(), "release", suite.ConfGorush.Core.Mode)
|
assert.Equal(suite.T(), "release", suite.ConfGorush.Core.Mode)
|
||||||
assert.Equal(suite.T(), false, suite.ConfGorush.Core.SSL)
|
assert.Equal(suite.T(), false, suite.ConfGorush.Core.SSL)
|
||||||
assert.Equal(suite.T(), "cert.pem", suite.ConfGorush.Core.CertPath)
|
assert.Equal(suite.T(), "cert.pem", suite.ConfGorush.Core.CertPath)
|
||||||
assert.Equal(suite.T(), "key.pem", suite.ConfGorush.Core.KeyPath)
|
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)
|
assert.Equal(suite.T(), "", suite.ConfGorush.Core.HTTPProxy)
|
||||||
// Pid
|
// Pid
|
||||||
assert.Equal(suite.T(), false, suite.ConfGorush.Core.PID.Enabled)
|
assert.Equal(suite.T(), false, suite.ConfGorush.Core.PID.Enabled)
|
||||||
|
|
|
@ -236,6 +236,6 @@ func main() {
|
||||||
|
|
||||||
gorush.InitAppStatus()
|
gorush.InitAppStatus()
|
||||||
gorush.InitAPNSClient()
|
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()
|
gorush.RunHTTPServer()
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,10 +186,10 @@ func InitAPNSClient() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitWorkers for initialize all workers.
|
// 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)
|
LogAccess.Debug("worker number is ", workerNum, ", queue number is ", queueNum)
|
||||||
QueueNotification = make(chan PushNotification, queueNum)
|
QueueNotification = make(chan PushNotification, queueNum)
|
||||||
for i := 0; i < workerNum; i++ {
|
for i := int64(0); i < workerNum; i++ {
|
||||||
go startWorker()
|
go startWorker()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -329,7 +329,7 @@ func TestOverwriteAndroidAPIKey(t *testing.T) {
|
||||||
func TestSenMultipleNotifications(t *testing.T) {
|
func TestSenMultipleNotifications(t *testing.T) {
|
||||||
PushConf = config.BuildDefaultPushConf()
|
PushConf = config.BuildDefaultPushConf()
|
||||||
|
|
||||||
InitWorkers(2, 2)
|
InitWorkers(int64(2), 2)
|
||||||
|
|
||||||
PushConf.Ios.Enabled = true
|
PushConf.Ios.Enabled = true
|
||||||
PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem"
|
PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem"
|
||||||
|
|
|
@ -40,7 +40,7 @@ func pushHandler(c *gin.Context) {
|
||||||
return
|
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)
|
msg = fmt.Sprintf("Number of notifications(%d) over limit(%d)", len(form.Notifications), PushConf.Core.MaxNotification)
|
||||||
LogAccess.Debug(msg)
|
LogAccess.Debug(msg)
|
||||||
abortWithError(c, http.StatusBadRequest, msg)
|
abortWithError(c, http.StatusBadRequest, msg)
|
||||||
|
|
|
@ -151,7 +151,7 @@ func TestEmptyNotifications(t *testing.T) {
|
||||||
func TestOutOfRangeMaxNotifications(t *testing.T) {
|
func TestOutOfRangeMaxNotifications(t *testing.T) {
|
||||||
initTest()
|
initTest()
|
||||||
|
|
||||||
PushConf.Core.MaxNotification = 1
|
PushConf.Core.MaxNotification = int64(1)
|
||||||
|
|
||||||
r := gofight.New()
|
r := gofight.New()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue