Re: [go-nuts] How to wait for HTTP server to start?

2021-03-30 Thread Brian Candler
On Tuesday, 30 March 2021 at 11:50:07 UTC+1 cpu...@gmail.com wrote: > On Monday, March 29, 2021 at 9:05:50 PM UTC+2 rog wrote: > >> I often call net.Listen directly before calling Serve in a goroutine. >> That way you can connect to the server's socket immediately even though the >> server

Re: [go-nuts] How to wait for HTTP server to start?

2021-03-30 Thread cpu...@gmail.com
On Monday, March 29, 2021 at 9:05:50 PM UTC+2 rog wrote: > I often call net.Listen directly before calling Serve in a goroutine. That > way you can connect to the server's socket immediately even though the > server might take a while to get around to serving the request. > It seems this

Re: [go-nuts] How to wait for HTTP server to start?

2021-03-29 Thread roger peppe
I often call net.Listen directly before calling Serve in a goroutine. That way you can connect to the server's socket immediately even though the server might take a while to get around to serving the request. Look at how net/http/httptest does it. On Sat, 27 Mar 2021, 14:13 cpu...@gmail.com,

Re: [go-nuts] How to wait for HTTP server to start?

2021-03-29 Thread Jesper Louis Andersen
On Sat, Mar 27, 2021 at 3:19 PM 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > 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

Re: [go-nuts] How to wait for HTTP server to start?

2021-03-27 Thread 'Axel Wagner' via golang-nuts
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

[go-nuts] How to wait for HTTP server to start?

2021-03-27 Thread cpu...@gmail.com
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