gohttpserver/internal/server/handleindex.go

22 lines
467 B
Go
Raw Normal View History

package server
2020-09-30 06:35:07 +00:00
import (
2020-10-29 00:47:37 +00:00
"html/template"
"log"
2020-09-30 06:35:07 +00:00
"net/http"
"git.eeqj.de/sneak/gohttpserver/templates"
2020-09-30 06:35:07 +00:00
)
func (s *server) 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 {
2020-10-29 00:47:37 +00:00
log.Println(err.Error())
http.Error(w, http.StatusText(500), 500)
2020-10-28 23:46:22 +00:00
}
2020-09-30 06:35:07 +00:00
}
}