This commit is contained in:
2023-08-25 15:06:46 +08:00
parent 993b893be4
commit 84cf2c8824
3 changed files with 52 additions and 0 deletions

View File

@@ -41,6 +41,18 @@ type YamlConfig struct {
KeyFile string `yaml:"keyFile"`
} `yaml:"rest"`
WebServer struct {
Enabled bool `yaml:"enabled"`
RootDir string `yaml:"rootDir"`
Listen []struct {
Addr string `yaml:"addr"`
Schema string `yaml:"schema"`
CaFile string `yaml:"caFile"`
CertFile string `yaml:"certFile"`
KeyFile string `yaml:"keyFile"`
} `yaml:"listen"`
} `yaml:"webServer"`
Database DbConfig `yaml:"database"`
OMC struct {

View File

@@ -22,6 +22,18 @@ rest:
certFile: ./etc/certs/tsa-omc.crt
keyFile: ./etc/certs/tsa-omc_pri.key
webServer:
enabled: true
rootDir: d:/local.git/fe.ems
listen:
- addr: :8080
schema: http
- addr: :9090
schema: https
caFile: ./etc/certs/rootca.crt
certFile: ./etc/certs/tsa-omc.crt
keyFile: ./etc/certs/tsa-omc_pri.key
database:
type: mysql
user: root

View File

@@ -110,6 +110,22 @@ func HttpListenConfigTLS(addr, caFile, certFile, keyFile string, router http.Han
}
}
func HttpListenWebServerTLS(addr, certFile, keyFile string) {
err := http.ListenAndServeTLS(addr, certFile, keyFile, nil)
if err != nil {
fmt.Println("ListenAndServeTLS err:", err)
os.Exit(7)
}
}
func HttpListenWebServer(addr string) {
err := http.ListenAndServe(addr, nil)
if err != nil {
fmt.Println("ListenAndServe err:", err)
os.Exit(7)
}
}
func main() {
conf := config.GetYamlConfig()
@@ -175,5 +191,17 @@ func main() {
}
}
if conf.WebServer.Enabled {
fs := http.FileServer(http.Dir(conf.WebServer.RootDir))
http.Handle("/", fs)
for _, listen := range conf.WebServer.Listen {
if strings.ToLower(listen.Schema) == "https" {
go HttpListenWebServerTLS(listen.Addr, listen.CertFile, listen.KeyFile)
} else {
go HttpListenWebServer(listen.Addr)
}
}
}
select {}
}