The best way to do it is probably by making an HTTP request and see if it succeeds. In production, it's always a good idea to have a health check endpoint anyways. So some service manager can check if it's alive and restart it if necessary. Or so that a load balancer doesn't send traffic until the service is healthy. The advantage is that you can determine yourself what you consider "healthy". That is, if you want to warm up some cache or connect to some backend, you can wait for that before the health-check endpoint returns true.
On Sat, Mar 27, 2021 at 3:14 PM cpu...@gmail.com <cpui...@gmail.com> wrote: > The typical Go tutorials pattern for starting a server is something like > > log.Fatal(http.ListenAndServe(":8080")) > > But what if the application needs to do other things after the server is > started? It seems there is virtually no method to wait for the server > actually start listening to requests? > > I'm probably missing something and would appreciate a hint. > > Thanks, > Andi > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/a40222e3-e4b3-4996-8232-045fcff43b77n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/a40222e3-e4b3-4996-8232-045fcff43b77n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfGRVP5sv-9Oxgjn26w8wo_8yq0dU3aXBt-uobONFCP17Q%40mail.gmail.com.