diff options
-rw-r--r-- | config/config.json | 2 | ||||
-rw-r--r-- | server.go | 19 |
2 files changed, 18 insertions, 3 deletions
diff --git a/config/config.json b/config/config.json index 102bda3..09243ed 100644 --- a/config/config.json +++ b/config/config.json @@ -1,5 +1,5 @@ { - "host":["localhost"], + "hosts":["localhost"], "allow-hidden": true, "hide-hidden": true, "auth": true, @@ -7,6 +7,7 @@ import ( "os" "io" "html/template" + "sync" "flag" "path" "net/url" @@ -489,9 +490,23 @@ func main() { return } - fmt.Println("Launch server on port:", port) http.HandleFunc("/", handleMethod) - log.Fatal(http.ListenAndServe(":" + strconv.Itoa(port), nil)) + if len(config.Config.Hostnames) == 0 { + fmt.Println("Error: No hostnames precised\nEmpty will be set", port) + config.Config.Hostnames = []string{""} + } + + var wg sync.WaitGroup + wg.Add(len(config.Config.Hostnames)) + + for _, host := range config.Config.Hostnames { + go func(host string) { + defer wg.Done() + fmt.Println("Launch server listen on " + host + ":" + strconv.Itoa(port)) + log.Fatal(http.ListenAndServe(host + ":" + strconv.Itoa(port), nil)) + }(host) + } + wg.Wait() fmt.Println("Bye bye") } |