mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-20 17:57:54 +00:00
feat[Https]: added https support (#113)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user