Address on listen and server method
Closed this issue · 2 comments
Hi Mat
Following your book, I have a question related to the function http.ListenAndSeve()
If you see in my chat project I build and run the app inside a Docker container
but using my address "localhost:8080" in the function does't work inside the container. (it is not visible out of the container)
http.ListenAndServe("localhost:8080", nil)
This way works (ehernandez-xk/bp_app@4d5f9c8)
http.ListenAndServe(":8080", nil)
What does the functions do when ":8080"?
By the way, Your book is awesome!
Thank you, I'm glad you're enjoying it. I'd love a review if you have time.
If you specify localhost:8080
as the endpoint, it will check to ensure the host is localhost
. For Docker and other environments (like when it's hosted on another domain) it won't necessarily be bound to the right place.
So :8080
is like saying: Bind to port :8080 regardless of the incoming host name.
You can also do IP addresses too: 123.234.345.456:8080
and it will only work when hosted at that address.
This is more of a TCP thing than Go.