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 ( import (
"flag" "flag"
"fmt"
"log" "log"
"net/http" "net/http"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv"
) )
var ( var (
host = flag.String("host", "", "host name") httpAddr = flag.String("http", ":8000", "HTTP address")
port = flag.Int("port", 8000, "port number")
) )
func init() { func init() {
@ -42,10 +39,5 @@ func init() {
func main() { func main() {
http.Handle("/", http.FileServer(http.Dir(rootPath))) http.Handle("/", http.FileServer(http.Dir(rootPath)))
if *host == "" { log.Fatal(http.ListenAndServe(*httpAddr, nil))
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))
} }

View File

@ -28,13 +28,11 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv"
"time" "time"
) )
var ( var (
host = flag.String("host", "", "host name") httpAddr = flag.String("http", ":8000", "HTTP address")
port = flag.Int("port", 8000, "port number")
) )
func init() { func init() {
@ -168,10 +166,5 @@ func main() {
http.HandleFunc("/main.js", serveMainJS) http.HandleFunc("/main.js", serveMainJS)
http.HandleFunc("/main.js.map", serveMainJSMap) http.HandleFunc("/main.js.map", serveMainJSMap)
http.HandleFunc("/", serveFileHandle) http.HandleFunc("/", serveFileHandle)
if *host == "" { log.Fatal(http.ListenAndServe(*httpAddr, nil))
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))
} }