fix #15 support ssl server.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
2e7255ccd1
commit
2604c07126
|
@ -28,3 +28,5 @@ key.pem
|
|||
config.yaml
|
||||
bin/*
|
||||
.DS_Store
|
||||
*.cert
|
||||
*.key
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue