website/pkg/controller/index/static.go

22 lines
569 B
Go
Raw Normal View History

2022-08-16 05:33:17 +00:00
package index
import (
"net/http"
2022-08-26 04:21:46 +00:00
"code.nonshy.com/nonshy/website/pkg/templates"
2022-08-16 05:33:17 +00:00
)
2023-02-06 04:26:36 +00:00
// StaticTemplate creates a simple controller that loads a Go html/template
// such as "about.html" relative to the web/templates path.
func StaticTemplate(filename string) func() http.HandlerFunc {
return func() http.HandlerFunc {
tmpl := templates.Must(filename)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := tmpl.Execute(w, r, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
}
2022-08-16 05:33:17 +00:00
}