summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2021-05-16 04:12:17 +0200
committerache <ache@ache.one>2021-05-16 04:13:28 +0200
commitcb41e56c7b7f28616c9c1960c4e97fa6de655df5 (patch)
tree32cb10b50b0d6a42779c3e61b97423870789bf1e
parentLog moving (diff)
Deal with hostnames
-rw-r--r--config/config.json2
-rw-r--r--server.go19
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")
}