Added http://hostname:port/ printout when server starts.
This commit is contained in:
parent
59b496b66e
commit
c3bcf30890
7
main.go
7
main.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var port = flag.Int("port", 8000, "port from which to serve")
|
var port = flag.Int("port", 8000, "port from which to serve")
|
||||||
@ -18,9 +19,13 @@ func logger(h http.Handler) http.Handler {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
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)
|
addr := fmt.Sprintf(":%d", *port)
|
||||||
fh := http.FileServer(http.Dir("./"))
|
fh := http.FileServer(http.Dir("./"))
|
||||||
http.ListenAndServe(":8080", logger(fh))
|
|
||||||
if err := http.ListenAndServe(addr, logger(fh)); err != nil {
|
if err := http.ListenAndServe(addr, logger(fh)); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user