Expose log.Fatal

The helper func log.Fatal does two things, logs and then exits the application. We are going to evolve our logging and the error handling down the road so let's not use the helper.
"log" "net/http" + "os" ) func main() { @@ -11,5 +12,9 @@ func main() { router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello, World!") }) - log.Fatal(http.ListenAndServe(":8080", router)) + err := http.ListenAndServe(":8080", router) + if err != nil { + log.Print(err) + os.Exit(1) + } }
prev toc next