Skip to content

Instantly share code, notes, and snippets.

@DeedleFake
Created November 22, 2023 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeedleFake/5b9e14db879d20806f608d3a12445a8d to your computer and use it in GitHub Desktop.
Save DeedleFake/5b9e14db879d20806f608d3a12445a8d to your computer and use it in GitHub Desktop.
Templ and Formam handler creation function.
func FormHandler[T any](f func(T) templ.Component) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
req.ParseForm()
var data T
d := formam.NewDecoder(nil)
d.Decode(req.Form, &data)
// TODO: Handle errors.
templ.Handler(f(data)).ServeHTTP(rw, req)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment