O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it…

  1. Create http-server.go, where we will create a simple HTTP server that will render Hello World! browsing http://ec2-instance-public-dns:80 or executing curl -X GET http://ec2-instance-public-dns:80 from the command line, as follows:
package mainimport (  "fmt"  "log"  "net/http")const (  CONN_PORT = "80")func helloWorld(w http.ResponseWriter, r *http.Request) {  fmt.Fprintf(w, "Hello World!")}func main() {   http.HandleFunc("/", helloWorld)  err := http.ListenAndServe(":"+CONN_PORT, nil)  if err != nil   {    log.Fatal("error starting http server : ", err)    return  }}

With everything in place, the directory structure should look like the following:

  1. Copy http-server.go from the local machine directory to an EC2 user home (/home/ec2-user ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required