I found the answer with the help of a fellow Gopher from the community.
The line of code containing srv.ListenAndServe()
is a blocking line of code causing the log after this line of code not to happen.
In my original code I demonstrated in my earlier blog I had this log in front of the line with srv.ListenAndServe()
. Therefore in that example the same code was logging to console as expected.
So after all it was a silly mistake which you can easily read over many times. Basically 2 lines of code where swapped and I forgot about the blocking behavior of http.ListenAndServe()
.
KEY takeaway:
http.ListenAndServe() is blocking by definition and therefore will not run any code after that line.
solved Web server graceful shutdown not working as expected