Skip to content

Commit 37f0c49

Browse files
authored
Merge pull request #73 from IAmAnubhavSaini/fix-72
Fixes #72. Update URL, introduce error when ListenAndServe fail.
2 parents 624b416 + 2580bfa commit 37f0c49

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)