A blog post from 2014 explains quite nicely how one can achieve graceful server stops and restarts in Go, that is, how to implement a server process that allows running requests to finish before exiting the application. We will also want to deploy new binaries without interrupting running requests and without any noticeable server downtime.
There are tools for this and in the past, I’ve used a combination of manners and goagain, along with some additional code on my end. With the Shutdown() function introduced in Go1.8, things got a lot easier. All that code can now be condensed into one page.
I’ve put it all in a gist which can be found here. All the documentation you will need is in there.