package main import ( "fmt" "log" "net/http" "os" ) func main() { host := os.Getenv("HOST") if host == "" { host = "0.0.0.0" } port := os.Getenv("PORT") if port == "" { port = "8000" } address := host + ":" + port router := http.NewServeMux() router.HandleFunc("/", handleIndex) router.HandleFunc("/subscribe", handleSubscribe) log.Println("Starting server on", address) http.ListenAndServe(address, router) } func handleIndex(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, ` Main page

Hello

A simple landing page.
Subscribe to our newsletter
Live chat
`) } func handleSubscribe(w http.ResponseWriter, r *http.Request) { email := r.FormValue("email") fmt.Fprintf(w, ` Confirmation email sent to %v `, email) }