From 45af07d08b15dbfb69f16be08406d55cd2e6cac2 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 10 Sep 2017 00:06:39 +0900 Subject: [PATCH] docs: Add 'host' parameter --- _docs/server/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/_docs/server/main.go b/_docs/server/main.go index fee92a15e..080b8980d 100644 --- a/_docs/server/main.go +++ b/_docs/server/main.go @@ -24,7 +24,10 @@ import ( "strconv" ) -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() @@ -39,6 +42,10 @@ func init() { func main() { http.Handle("/", http.FileServer(http.Dir(rootPath))) - 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)) }