main.go 673 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "html/template"
  4. "log"
  5. "net/http"
  6. )
  7. type server struct {
  8. template *template.Template
  9. }
  10. func main() {
  11. t := template.Must(template.ParseFiles("templates/main.html"))
  12. s := server{template: t}
  13. http.HandleFunc("/", s.handleRoot)
  14. http.Handle("/resource/", http.FileServer(http.Dir(".")))
  15. log.Fatal(http.ListenAndServeTLS(":8443", "certs/localhost.cert", "certs/localhost.key", nil))
  16. }
  17. func (s *server) handleRoot(w http.ResponseWriter, r *http.Request) {
  18. if r.RequestURI != "/" {
  19. http.NotFound(w, r)
  20. return
  21. }
  22. w.Header().Set("Content-Type", "text/html")
  23. err := s.template.Execute(w, "Devoxx")
  24. if err != nil {
  25. log.Println(err)
  26. }
  27. }