Added http://hostname:port/ printout when server starts.

This commit is contained in:
Stephen McQuay 2013-10-21 19:26:16 -07:00
parent 59b496b66e
commit c3bcf30890

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"os"
)
var port = flag.Int("port", 8000, "port from which to serve")
@ -18,9 +19,13 @@ func logger(h http.Handler) http.Handler {
func main() {
flag.Parse()
hostname, err := os.Hostname()
if err != nil {
log.Fatal("problem getting hostname:", err)
}
log.Printf("serving on: http://%s:%d/", hostname, *port)
addr := fmt.Sprintf(":%d", *port)
fh := http.FileServer(http.Dir("./"))
http.ListenAndServe(":8080", logger(fh))
if err := http.ListenAndServe(addr, logger(fh)); err != nil {
log.Fatal(err)
}