Graceful Go HTTP Server Shutdown

Generally when I see http servers written by new Go programmers, I see net/http used in a manner that does not handle shutdowns gracefully. It seems most copy verbatim the Go documentation example into something like this: func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Ok") }) log.Fatal(http.ListenAndServe(":8080", nil)) } While this works, it glosses over an important aspect on how this applications exits: the program running this one.
Read more →