From 6c10251a45d4ea01da9b1d8f89abd06a014c01ab Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 27 Aug 2017 05:22:08 +0900 Subject: [PATCH] examples/_server: Enable to specify host --- examples/_server/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/_server/main.go b/examples/_server/main.go index 3cbbd87ea..7d5544f57 100644 --- a/examples/_server/main.go +++ b/examples/_server/main.go @@ -32,7 +32,10 @@ import ( "time" ) -var port = flag.Int("port", 8000, "port number") +var ( + host = flag.String("host", "", "host name") + port = flag.Int("port", 8000, "port number") +) func init() { flag.Parse() @@ -165,6 +168,10 @@ func main() { http.HandleFunc("/main.js", serveMainJS) http.HandleFunc("/main.js.map", serveMainJSMap) http.HandleFunc("/", serveFileHandle) - fmt.Printf("http://localhost:%d/\n", *port) - log.Fatal(http.ListenAndServe("localhost:"+strconv.Itoa(*port), nil)) + if *host == "" { + fmt.Printf("http://127.0.0.1:%d/\n", *port) + } else { + fmt.Printf("http://%s:%d/\n", *host, *port) + } + log.Fatal(http.ListenAndServe(*host+":"+strconv.Itoa(*port), nil)) }