Skip to content

Instantly share code, notes, and snippets.

@bmcculley
Created September 3, 2021 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmcculley/ab50aca899e0a12a34dcdadbf63de11d to your computer and use it in GitHub Desktop.
Save bmcculley/ab50aca899e0a12a34dcdadbf63de11d to your computer and use it in GitHub Desktop.
AWS example web server for learning
package main
import (
"fmt"
"net/http"
"os"
)
var hostname string
func setHostName() {
var err error
hostname, err = os.Hostname()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func hostNameServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello from %s!", hostname)
}
func main() {
setHostName()
http.HandleFunc("/", hostNameServer)
http.ListenAndServe(":80", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment