# httpin [](https://codecov.io/gh/ggicci/httpin) HTTP Input for Go - Decode an HTTP request into a custom struct **Define the struct for your input and then fetch your data!** ## Quick View
BEFORE (use net/http) | AFTER (use httpin) |
---|---|
```go func ListUsers(rw http.ResponseWriter, r *http.Request) { page, err := strconv.ParseInt(r.FormValue("page"), 10, 64) if err != nil { // Invalid parameter: page. return } perPage, err := strconv.ParseInt(r.FormValue("per_page"), 10, 64) if err != nil { // Invalid parameter: per_page. return } isMember, err := strconv.ParseBool(r.FormValue("is_member")) if err != nil { // Invalid parameter: is_member. return } // Do sth. } ``` | ```go type ListUsersInput struct { Page int `in:"form=page"` PerPage int `in:"form=per_page"` IsMember bool `in:"form=is_member"` } func ListUsers(rw http.ResponseWriter, r *http.Request) { inputInterface, err := httpin.New(ListUsersInput{}).Decode(r) if err != nil { // Error occurred, `err` can be type of *httpin.InvalidFieldError // Do sth. return } input := interfaceInput.(*ListUsersInput) // Do sth. } ``` |