gohttpserver/internal/handlers/handleindex.go

21 lines
466 B
Go
Raw Normal View History

2022-11-28 03:59:20 +00:00
package handlers
2020-09-30 06:35:07 +00:00
import (
2020-10-29 00:47:37 +00:00
"html/template"
2020-09-30 06:35:07 +00:00
"net/http"
"git.eeqj.de/sneak/gohttpserver/templates"
2020-09-30 06:35:07 +00:00
)
2022-11-28 03:59:20 +00:00
func (s *Handlers) HandleIndex() http.HandlerFunc {
indexTemplate := template.Must(template.New("index").Parse(templates.MustString("index.html")))
2020-10-29 00:47:37 +00:00
2020-09-30 06:35:07 +00:00
return func(w http.ResponseWriter, r *http.Request) {
2020-10-29 00:47:37 +00:00
err := indexTemplate.ExecuteTemplate(w, "index", nil)
2020-10-28 23:46:22 +00:00
if err != nil {
2022-11-28 03:59:20 +00:00
s.log.Println(err.Error())
2020-10-29 00:47:37 +00:00
http.Error(w, http.StatusText(500), 500)
2020-10-28 23:46:22 +00:00
}
2020-09-30 06:35:07 +00:00
}
}