Use an -http address arguments for servers

Fixes #510
This commit is contained in:
Hajime Hoshi 2018-02-23 01:44:14 +09:00
parent 591e0ad995
commit ed80286431
2 changed files with 4 additions and 19 deletions

View File

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

View File

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