Created
November 22, 2023 17:18
-
-
Save DeedleFake/5b9e14db879d20806f608d3a12445a8d to your computer and use it in GitHub Desktop.
Templ and Formam handler creation function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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