Commit ca14394e by Iwasaki Yudai

Use `net.JoinHostPort` for better IPv6 handling

1 parent 5d2cdd27
Showing with 3 additions and 7 deletions
......@@ -95,7 +95,7 @@ func (app *App) Run() error {
path += "/" + generateRandomString(8)
}
endpoint := app.options.Address + ":" + app.options.Port
endpoint := net.JoinHostPort(app.options.Address, app.options.Port)
wsHandler := http.HandlerFunc(app.handleWS)
staticHandler := http.FileServer(
......@@ -123,7 +123,7 @@ func (app *App) Run() error {
log.Printf("URL: %s", "http://"+endpoint+path+"/")
} else {
for _, address := range listAddresses() {
log.Printf("URL: %s", "http://"+address+":"+app.options.Port+path+"/")
log.Printf("URL: %s", "http://"+net.JoinHostPort(address, app.options.Port)+path+"/")
}
}
if err := http.ListenAndServe(endpoint, siteHandler); err != nil {
......@@ -221,11 +221,7 @@ func listAddresses() (addresses []string) {
for _, ifAddr := range ifAddrs {
switch v := ifAddr.(type) {
case *net.IPNet:
if v.IP.To4() == nil {
addresses = append(addresses, "["+v.IP.String()+"]")
} else {
addresses = append(addresses, v.IP.String())
}
addresses = append(addresses, v.IP.String())
case *net.IPAddr:
addresses = append(addresses, v.IP.String())
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!