feat[Https]: added https support (#113)

This commit is contained in:
zhangwenjian
2020-06-11 23:56:05 +08:00
parent 5d69b32119
commit 0177fb17b7
9 changed files with 89 additions and 5 deletions
+21 -1
View File
@@ -11,6 +11,8 @@ type Application struct {
JwtSecret string
Mode string
DemoMsg string
Domain string
IsHttps bool
}
func InitApplication(cfg *viper.Viper) *Application {
@@ -18,12 +20,30 @@ func InitApplication(cfg *viper.Viper) *Application {
ReadTimeout: cfg.GetInt("readTimeout"),
WriterTimeout: cfg.GetInt("writerTimeout"),
Host: cfg.GetString("host"),
Port: cfg.GetString("port"),
Port: portDefault(cfg),
Name: cfg.GetString("name"),
JwtSecret: cfg.GetString("jwtSecret"),
Mode: cfg.GetString("mode"),
DemoMsg: cfg.GetString("demoMsg"),
Domain: cfg.GetString("domain"),
IsHttps: cfg.GetBool("ishttps"),
}
}
var ApplicationConfig = new(Application)
func portDefault(cfg *viper.Viper) string {
if cfg.GetString("port") == "" {
return "8000"
} else {
return cfg.GetString("port")
}
}
func isHttpsDefault(cfg *viper.Viper) bool {
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false{
return false
} else {
return true
}
}
+7
View File
@@ -13,6 +13,7 @@ var cfgDatabase *viper.Viper
var cfgApplication *viper.Viper
var cfgJwt *viper.Viper
var cfgLog *viper.Viper
var cfgSsl *viper.Viper
//载入配置文件
@@ -53,6 +54,12 @@ func ConfigSetup(path string) {
panic("config not found settings.log")
}
LogConfig = InitLog(cfgLog)
cfgSsl = viper.Sub("settings.ssl")
if cfgSsl == nil {
panic("config not found settings.ssl")
}
SslConfig = InitSsl(cfgSsl)
}
+17
View File
@@ -0,0 +1,17 @@
package config
import "github.com/spf13/viper"
type Ssl struct {
KeyStr string
Pem string
}
func InitSsl(cfg *viper.Viper) *Ssl {
return &Ssl{
KeyStr: cfg.GetString("key"),
Pem: cfg.GetString("pem"),
}
}
var SslConfig = new(Ssl)