package main
import (
"html/template"
"log"
"net/http"
)
type server struct {
template *template.Template
}
func main() {
t := template.Must(template.ParseFiles("templates/main.html"))
s := server{template: t}
http.HandleFunc("/", s.handleRoot)
http.Handle("/resources/", http.FileServer(http.Dir(".")))
log.Println("Listening on https://localhost:8443")
err := http.ListenAndServeTLS(":8443", "certs/localhost.cert", "certs/localhost.key", nil)
log.Fatal(err)
}
func (s *server) handleRoot(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
if r.RequestURI != "/" {
http.NotFound(w, r)
return
}
err := s.template.Execute(w, "Vrolijk pasen!")
if err != nil {
log.Println(err)
}
}