jerome - not sure that the code you provided fully answers the OP's problem. I think you'd need to craft an http request and get a response to really KNOW that the server is indeed responding. If you do that as a replacement for where you have the "select {}" then I think you've got it.
Note, the http request need not be complicated. A simple "echo" style handler would do the trick. As soon as you get the echo back then you know your server is ready to start handling other types of potentially more complex requests. If the server has a TON of stuff (seconds to minutes of initialization) you can make the echo server wait till all the prelim's are done first before sending the echo reply. After startup you can also use the echo as a simple test of whether the server is at least running - even if more complicated requests are failing. On Saturday, March 27, 2021 at 1:53:47 PM UTC-4 jerome....@gmail.com wrote: > When I want to ensure that the HTTP server is started (or if I want > additional stuff), I do this : > > https://play.golang.org/p/mX0OsNWFf-f > > Le samedi 27 mars 2021 à 15:13:40 UTC+1, cpu...@gmail.com a écrit : > >> 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/ffeaa43b-bde3-4524-ae88-b1e7292108f1n%40googlegroups.com.