examples/_server: Enable to specify host

This commit is contained in:
Hajime Hoshi 2017-08-27 05:22:08 +09:00
parent fabafff7ed
commit 6c10251a45

View File

@ -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))
}