I know that Golang contain native built-in web server(net/http) that can be used as server without using external web servers(apache,nginx,etc). For local development, you simply run http.ListenAndServe
and your server is ready locally.
My question is, How to set up your golang app to be accessed by others publicly without the need of external web servers?
In your golang code, you don't need to do anything else except specifying the port your app listening to. After setting the port(e.g :8080
), you need to do these things to make it accessible:
10.50.50.10:8080
You do not need to change anything about your application, just open the port in your server firewall and change the IP in http.ListenAndServe to 0.0.0.0 (or just let it out entirely), for example: http.ListenAndServe(":80")