HTTP

api rest http

Anonymous Server

MacOS will throw firewall alerts to allow connectivity every time a binary is run that doesn’t provide the server address.

  • ❌ What throws the error: http.ListenAndServe(":"+port, nil)
  • ✔️ What doesn’t throw an error: http.ListenAndServe("127.0.0.1:"+port, nil)

While this might be problematic to iron out as a variable if running inside a Docker container needing to talk to the host, it works well for running the binary locally without much change. If you are running inside Docker and need 127.0.0.1 to resolve to the host directly, then you’ll need to handle that differently. See I want to connect from a container to a service on the host.

I ran this problem through chatGPT and it provided a nice explanation.1

Footnotes

  1. This is an incredible example of it jump-starting debugging efforts. The level of effort to get a quick answer was much faster than Google. While it may “hallucinate”, this is a good example of quick information that can help and let you move on.