get_root.go 401 B

123456789101112131415161718192021
  1. package web
  2. import (
  3. "io"
  4. "log"
  5. "net/http"
  6. "strings"
  7. )
  8. // handleGetRoot handles path /
  9. func handleGetRoot(w http.ResponseWriter, r *http.Request) {
  10. sw := &strings.Builder{}
  11. err := tmpl.ExecuteTemplate(sw, "home", nil)
  12. if err != nil {
  13. log.Println(err)
  14. w.WriteHeader(http.StatusInternalServerError)
  15. } else {
  16. w.WriteHeader(http.StatusOK)
  17. io.Copy(w, strings.NewReader(sw.String()))
  18. }
  19. }