Created
May 17, 2021 06:50
-
-
Save ggicci/eb1072d876e0214df1dc189785284def to your computer and use it in GitHub Desktop.
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
// 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