Skip to content

Commit 2580bfa

Browse files
author
Anubhav Saini
committed
Fixes #72. Update URL, introduce error when ListenAndServe fail.
1. The URL where the server is running is updated so that it can be clicked from the terminal, in case the terminal supports it. 2. The error is thrown if the port cannot be bound by the tutorial server.
1 parent 624b416 commit 2580bfa

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,19 @@ func handle(root string) func(w http.ResponseWriter, req *http.Request) {
382382
}
383383

384384
var (
385-
host = flag.String("host", "localhost:8000", "Serving host")
385+
protocol = "http"
386+
address = "localhost:8000"
387+
host = flag.String("host", address, "Serving host")
386388
)
387389

388390
func main() {
389391
flag.Parse()
390-
fmt.Println("Serving Go+ tutorial at", *host)
392+
fmt.Printf("Serving Go+ tutorial at %s://%s\n", protocol, *host)
391393
http.HandleFunc("/", handle("."))
392-
http.ListenAndServe(*host, nil)
394+
err := http.ListenAndServe(*host, nil)
395+
if err != nil {
396+
log.Fatalf("Failed to start server at %s://%s.\nError: %s.", protocol, *host, err)
397+
}
393398
}
394399

395400
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)