33 lines
673 B
Go
33 lines
673 B
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
log.Printf("Defaulting to port %s \n", port)
|
|
}
|
|
|
|
http.HandleFunc("/", handleRoot)
|
|
if err := http.ListenAndServe(":"+port, nil); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
|
tmpl, err := template.ParseFiles("templates/index.html")
|
|
if err != nil {
|
|
http.Error(w, "Couldn't parse template file", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
err = tmpl.Execute(w, "Nothing lol")
|
|
if err != nil {
|
|
http.Error(w, "Failed to execute template", http.StatusInternalServerError)
|
|
}
|
|
}
|