From ed802864310142fa53de5865d4fa91cc92f334aa Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 23 Feb 2018 01:44:14 +0900 Subject: [PATCH] Use an -http address arguments for servers Fixes #510 --- _docs/server/main.go | 12 ++---------- examples/_server/main.go | 11 ++--------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/_docs/server/main.go b/_docs/server/main.go index 080b8980d..a5428a079 100644 --- a/_docs/server/main.go +++ b/_docs/server/main.go @@ -16,17 +16,14 @@ package main import ( "flag" - "fmt" "log" "net/http" "path/filepath" "runtime" - "strconv" ) var ( - host = flag.String("host", "", "host name") - port = flag.Int("port", 8000, "port number") + httpAddr = flag.String("http", ":8000", "HTTP address") ) func init() { @@ -42,10 +39,5 @@ func init() { func main() { http.Handle("/", http.FileServer(http.Dir(rootPath))) - 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)) + log.Fatal(http.ListenAndServe(*httpAddr, nil)) } diff --git a/examples/_server/main.go b/examples/_server/main.go index 7d5544f57..88606b7c7 100644 --- a/examples/_server/main.go +++ b/examples/_server/main.go @@ -28,13 +28,11 @@ import ( "os/exec" "path/filepath" "runtime" - "strconv" "time" ) var ( - host = flag.String("host", "", "host name") - port = flag.Int("port", 8000, "port number") + httpAddr = flag.String("http", ":8000", "HTTP address") ) func init() { @@ -168,10 +166,5 @@ func main() { http.HandleFunc("/main.js", serveMainJS) http.HandleFunc("/main.js.map", serveMainJSMap) http.HandleFunc("/", serveFileHandle) - 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)) + log.Fatal(http.ListenAndServe(*httpAddr, nil)) }