You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 line
484B

  1. package rex
  2. import (
  3. "net/http"
  4. "github.com/gorilla/schema"
  5. )
  6. var Schema = schema.NewDecoder()
  7. type Validator interface {
  8. Validate() error
  9. }
  10. // ParseForm parsed the raw query from the URL and updates request.Form,
  11. // decode the from to the given struct with Validator implemented.
  12. func ParseForm(r *http.Request, form Validator) (err error) {
  13. if err = r.ParseForm(); err == nil {
  14. if err = Schema.Decode(form, r.Form); err == nil {
  15. err = form.Validate()
  16. }
  17. }
  18. return
  19. }