diff --git a/restagent/config/config.go b/restagent/config/config.go index e87d8841..53320c3c 100644 --- a/restagent/config/config.go +++ b/restagent/config/config.go @@ -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 { diff --git a/restagent/etc/restconf.yaml b/restagent/etc/restconf.yaml index 38eeac66..ceb8a23a 100644 --- a/restagent/etc/restconf.yaml +++ b/restagent/etc/restconf.yaml @@ -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 diff --git a/restagent/restagent.go b/restagent/restagent.go index 94011906..c6fff4f5 100644 --- a/restagent/restagent.go +++ b/restagent/restagent.go @@ -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 {} }