Please tell me what I’m doing wrong, other programs run like this.
I compiled the sources into a binary file and run the server on ubuntu
chmod 777 webserver_linux_amd64
but not working…
in local machine this code work fine
CONN_HOST = "localhost"
CONN_PORT = "8089"
err = http.ListenAndServe(CONN_HOST+":"+CONN_PORT, nil)
maybe need to change CONN_HOST? How to define a host variable correctly for server? Or is there another method? or what could be the problem here?
Server as in like for AWS instance?
If yes use
Does the server not run? If so, what error do you get?
Or is it that you can not connect to it? Binding
localhost:8089 will only accept connections made through the loopback device. Usually you want to bind an IP that exist on a device that is routable from the outside world or
:: to bind all IPs.
I entered the server ip address instead of localhost and it all worked, maybe there is some function how can I do this to find out the server address?
Yes, you can find out ybout all available network interfaces using
net.Interfaces(), then you can iterate over them and use
net.interface.Addrs to get their IP addresses.
After that you’ll have a list of IP addresses, but you wont know which of them is publicly available.
The IP to bind to is usually given as a configuration option or simply
:: are used to bind to all available IP addresses.
Due to security reasons, I’d always bind to a single IP only once the software goes live.
I’m less strict about this when the host itself is not publicly available but only accessible through a loadbalancer/reverse proxy.