How to gracefully shutdown a Go HTTP server

The following code snippet of Go starts a simple HTTP server that responds with “Hello World” to every request it gets. 1 func main () { 2 server := & http . Server { 3 Addr : ":8080" , 4 Handler : http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { 5 w . Write ([] byte ( "
Hello World
" )) 6 }), 7 } 8 if err := server . ListenAndServe ();…