From 4df9ac80596a4df1534e3b12c973268c1d2c538d Mon Sep 17 00:00:00 2001 From: Iwasaki Yudai Date: Mon, 24 Aug 2015 05:34:56 +0900 Subject: [PATCH] Use `url.URL` for constructing URLs --- app/app.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 26610eb..bbc2074 100644 --- a/app/app.go +++ b/app/app.go @@ -10,6 +10,7 @@ import ( "math/big" "net" "net/http" + "net/url" "os" "os/exec" "strconv" @@ -120,10 +121,19 @@ func (app *App) Run() error { strings.Join(app.options.Command, " "), ) if app.options.Address != "" { - log.Printf("URL: %s", "http://"+endpoint+path+"/") + log.Printf( + "URL: %s", (&url.URL{Scheme: "http", Host: endpoint, Path: path + "/"}).String(), + ) } else { for _, address := range listAddresses() { - log.Printf("URL: %s", "http://"+net.JoinHostPort(address, app.options.Port)+path+"/") + log.Printf( + "URL: %s", + (&url.URL{ + Scheme: "http", + Host: net.JoinHostPort(address, app.options.Port), + Path: path + "/", + }).String(), + ) } } if err := http.ListenAndServe(endpoint, siteHandler); err != nil {