package main import ( "fmt" "log" "net/http" "os" ) func main() { http.HandleFunc("/", indexHandler) port := os.Getenv("PORT") if port == "" { port = "8080" log.Printf("Defaulting to port %s", port) } log.Printf("Listening on port %s", port) log.Printf("Open http://localhost:%s in the browser", port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) } func indexHandler(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/test" { _, err := fmt.Fprint(w, "Testing path") if err != nil { w.WriteHeader(http.StatusInternalServerError) } } else if r.URL.Path == "/" { _, err := fmt.Fprint(w, "Hello, World!!") if err != nil { w.WriteHeader(http.StatusInternalServerError) } } else { http.NotFound(w, r) return } }