Skip to content

Instantly share code, notes, and snippets.

@ggicci
Created May 17, 2021 06:50
Show Gist options
  • Save ggicci/eb1072d876e0214df1dc189785284def to your computer and use it in GitHub Desktop.
Save ggicci/eb1072d876e0214df1dc189785284def to your computer and use it in GitHub Desktop.
// 1. Define you input struct
type ListUsersInput struct {
Page int `in:"form=page"`
PerPage int `in:"form=per_page"`
IsMember bool `in:"form=is_member"`
}
// 2. Bind this input struct with an HTTP handler
func init() {
http.Handle("/users", alice.New(
httpin.NewInput(ListUsersInput{}),
).ThenFunc(ListUsers))
}
// 3. Use the input in the handler, all the parsing stuff are handled by httpin
func ListUsers(rw http.ResponseWriter, r *http.Request) {
input := r.Context().Value(httpin.Input).(*ListUsersInput)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment