How to use next available port in http.ListenAndServe
You may use port 0 to indicate you’re not specifying an exact port but you want a free, available port selected by the system: http.ListenAndServe(“:0”, nil) The problem with this is that you won’t be able to find out what port was assigned. So you need to create the net.Listener yourself (using the net.Listen() function), … Read more