From 44c5d29c3b5595ae59d3c19bb04beeecf7cb8a63 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 16 Oct 2013 17:49:35 -0400 Subject: [PATCH] Use net.JoinHostPort so IPv6 can be handled properly later. --- sockets.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sockets.go b/sockets.go index 016b994..b8c1316 100644 --- a/sockets.go +++ b/sockets.go @@ -24,6 +24,7 @@ import ( "fmt" "github.com/conformal/btcjson" "github.com/conformal/btcwire" + "net" "net/http" "sync" ) @@ -441,7 +442,7 @@ func FrontendListenAndServe() error { // TODO(jrick): We need some sort of authentication before websocket // connections are allowed, and perhaps TLS on the server as well. http.Handle("/frontend", websocket.Handler(frontendReqsNotifications)) - return http.ListenAndServe(fmt.Sprintf(":%s", cfg.SvrPort), nil) + return http.ListenAndServe(net.JoinHostPort("", cfg.SvrPort), nil) } // BtcdConnect connects to a running btcd instance over a websocket @@ -450,7 +451,7 @@ func FrontendListenAndServe() error { func BtcdConnect(reply chan error) { // btcd requires basic authorization, so we use a custom config with // the Authorization header set. - server := fmt.Sprintf("ws://localhost:%s/wallet", cfg.BtcdPort) + server := fmt.Sprintf("ws://%s/wallet", net.JoinHostPort("localhost", cfg.BtcdPort)) login := cfg.Username + ":" + cfg.Password auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login)) config, err := websocket.NewConfig(server, "http://localhost/")