summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorache <ache@ache.one>2021-05-16 05:35:14 +0200
committerache <ache@ache.one>2021-05-16 05:35:14 +0200
commitdffbda7fe483de7ec6843f1ffcf2f51faea444d5 (patch)
tree38995ee5d375205858627a1c2f213187dab39c7c /server.go
parentForce host with cli arg (diff)
Force IP version
Diffstat (limited to 'server.go')
-rw-r--r--server.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/server.go b/server.go
index eab1e75..0c50b92 100644
--- a/server.go
+++ b/server.go
@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
+ "net"
"os"
"io"
"html/template"
@@ -415,6 +416,10 @@ func main() {
var help, version bool
var port = -1
var host string
+ var ip_version = ""
+
+ var isV4 bool
+ var isV6 bool
helpString := `This is the help`
versionString := "0.0.0"
@@ -439,6 +444,8 @@ func main() {
flag.BoolVar(&version, "version", false, usageVersion)
flag.BoolVar(&version, "v", false, usageVersion+" (shorthand)")
+ flag.BoolVar(&isV4, "ipv4", false, "force use of IPv4")
+ flag.BoolVar(&isV6, "ipv6", false, "force use of IPv6")
flag.Parse()
if help {
@@ -474,6 +481,17 @@ func main() {
if host != "" {
config.Config.Hostnames = []string{host}
}
+ if isV4 {
+ if !isV6 {
+ ip_version = "tcp4"
+ } else {
+ fmt.Println("Can't be only IPv4 and IPv6")
+ return
+ }
+ } else if isV6 {
+ ip_version = "tcp6"
+ }
+
fmap := template.FuncMap{
"formatURL": encodeURL,
@@ -511,7 +529,16 @@ func main() {
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))
+ if ip_version != "" {
+ n, err := net.Listen(ip_version, host + ":" + strconv.Itoa(port))
+ if err == nil {
+ log.Fatal(http.Serve(n, nil))
+ } else {
+ fmt.Println(err)
+ }
+ } else {
+ log.Fatal(http.ListenAndServe(host + ":" + strconv.Itoa(port), nil))
+ }
}(host)
}
wg.Wait()