diff options
author | ache <ache@ache.one> | 2021-05-16 04:12:17 +0200 |
---|---|---|
committer | ache <ache@ache.one> | 2021-05-16 04:13:28 +0200 |
commit | cb41e56c7b7f28616c9c1960c4e97fa6de655df5 (patch) | |
tree | 32cb10b50b0d6a42779c3e61b97423870789bf1e /server.go | |
parent | Log moving (diff) |
Deal with hostnames
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -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") } |