diff --git a/.gitignore b/.gitignore index 9022144..0bfd2ac 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ key.pem config.yaml bin/* .DS_Store +*.cert +*.key diff --git a/config/apns.yaml b/config/apns.yaml index ad1ad11..7223614 100644 --- a/config/apns.yaml +++ b/config/apns.yaml @@ -2,6 +2,9 @@ core: port: "8088" notification_max: 100 production: true + ssl: false + cert_path: "cert.pem" + key_path: "key.pem" api: push_uri: "/api/push" diff --git a/gorush/config.go b/gorush/config.go index 310e1eb..ead7f44 100644 --- a/gorush/config.go +++ b/gorush/config.go @@ -17,6 +17,9 @@ type SectionCore struct { Port string `yaml:"port"` NotificationMax int `yaml:"notification_max"` Production bool `yaml:"production"` + SSL bool `yaml:"ssl"` + CertPath string `yaml:"cert_path"` + KeyPath string `yaml:"key_path"` } type SectionApi struct { @@ -43,6 +46,9 @@ func BuildDefaultPushConf() ConfYaml { conf.Core.Port = "8088" conf.Core.NotificationMax = 100 conf.Core.Production = true + conf.Core.SSL = false + conf.Core.CertPath = "cert.pem" + conf.Core.KeyPath = "key.pem" // Api conf.Api.PushUri = "/api/push" diff --git a/gorush/server.go b/gorush/server.go index 9bf5b74..079ab33 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -2,7 +2,6 @@ package gopush import ( api "github.com/appleboy/gin-status-api" - "github.com/braintree/manners" "github.com/gin-gonic/gin" "log" "net/http" @@ -59,5 +58,9 @@ func GetMainEngine() *gin.Engine { } func RunHTTPServer() { - manners.ListenAndServe(":"+PushConf.Core.Port, GetMainEngine()) + if PushConf.Core.SSL && PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" { + GetMainEngine().RunTLS(":"+PushConf.Core.Port, PushConf.Core.CertPath, PushConf.Core.KeyPath) + } else { + GetMainEngine().Run(":" + PushConf.Core.Port) + } }