From cb41e56c7b7f28616c9c1960c4e97fa6de655df5 Mon Sep 17 00:00:00 2001 From: ache Date: Sun, 16 May 2021 04:12:17 +0200 Subject: Deal with hostnames --- config/config.json | 2 +- 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, diff --git a/server.go b/server.go index 4bb2435..820a21a 100644 --- a/server.go +++ b/server.go @@ -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") } -- cgit v1.2.3