🎇 support https

pull/548/head
微凉 2021-12-01 00:19:06 +08:00
parent bd91acc5d0
commit 944941db10
2 changed files with 9 additions and 5 deletions

View File

@ -54,7 +54,12 @@ func main() {
server.InitApiRouter(r)
base := fmt.Sprintf("%s:%d", conf.Conf.Address, conf.Conf.Port)
log.Infof("start server @ %s", base)
err := r.Run(base)
var err error
if conf.Conf.Https {
err = r.RunTLS(base, conf.Conf.CertFile, conf.Conf.KeyFile)
} else {
err = r.Run(base)
}
if err != nil {
log.Errorf("failed to start: %s", err.Error())
}

View File

@ -14,6 +14,9 @@ type Config struct {
Address string `json:"address"`
Port int `json:"port"`
Database Database `json:"database"`
Https bool `json:"https"`
CertFile string `json:"cert_file"`
KeyFile string `json:"key_file"`
}
func DefaultConfig() *Config {
@ -22,11 +25,7 @@ func DefaultConfig() *Config {
Port: 5244,
Database: Database{
Type: "sqlite3",
User: "",
Password: "",
Host: "",
Port: 0,
Name: "",
TablePrefix: "x_",
DBFile: "data/data.db",
},