fix #15 support ssl server.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-03-28 14:40:48 +08:00
parent 2e7255ccd1
commit 2604c07126
4 changed files with 16 additions and 2 deletions

2
.gitignore vendored
View File

@ -28,3 +28,5 @@ key.pem
config.yaml
bin/*
.DS_Store
*.cert
*.key

View File

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

View File

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

View File

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