Deploying my first Go web app and had a few questions


Deploying my first Go web app and had a few questions

Let's say I'm buidling a really simple web server in Go. A minimal example would be:

package main import ( "fmt" "html" "log" "net/http" ) func main() { http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request){ fmt.Fprintf(w, "Hello") }) log.Fatal(http.ListenAndServe(":8080", nil)) } 

Locally I this with go run *.go and I can hit localhost:8080/hello to get a response.

I'd like to run this on a server somewhere, such as a VPS (e.g. 123.123.50.50)

  1. Should I build/compile this code into an executable and run it? Or is it sufficient to use go run *.go on the remote server as well? If not, how does one build and run the binary?

  2. Once I get it running, would my page automatically be available at http://ift.tt/2wzjAIR? Or do I need to set up something like nginx to route all the incoming requests to my Go process that's running as a daemon?

Thanks!

Submitted August 11, 2017 at 11:49AM by lefthandpisces
via reddit http://ift.tt/2uvQ7yd

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s