gohttpserver/httpserver/handleindex.go

20 lines
432 B
Go
Raw Normal View History

2020-09-30 06:35:07 +00:00
package httpserver
import (
2020-10-29 00:47:37 +00:00
"html/template"
"log"
2020-09-30 06:35:07 +00:00
"net/http"
)
func (s *server) handleIndex() http.HandlerFunc {
2020-10-29 00:47:37 +00:00
indexTemplate := template.Must(template.New("index").Parse(s.templateFiles.MustString("index.html")))
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
}
}