Skip to content

Commit

Permalink
start: make http server's listening host/port compatible with IPv6 (#14)
Browse files Browse the repository at this point in the history
previously, a command like this to listen on IPv6 loopback:

    HOST=::1 PORT=7447 go run ./basic/

would exit immediately because ::1:7447 is an invalid address.

IPv6 addresses contain columns, so a simple host + port concatenation
doesn't work. net.JoinHostPort is a function to do exactly that.
  • Loading branch information
x1ddos authored Dec 24, 2022
1 parent 642710f commit 932a9b6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package relayer

import (
"net"
"fmt"
"net/http"
"os"
Expand Down Expand Up @@ -72,7 +73,7 @@ func StartConf(s Settings, relay Relay) error {
// start http server
srv := &http.Server{
Handler: cors.Default().Handler(Router),
Addr: s.Host + ":" + s.Port,
Addr: net.JoinHostPort(s.Host, s.Port),
WriteTimeout: 2 * time.Second,
ReadTimeout: 2 * time.Second,
IdleTimeout: 30 * time.Second,
Expand Down

0 comments on commit 932a9b6

Please sign in to comment.