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
472B

  1. package form
  2. import (
  3. "net/http"
  4. . "github.com/gorilla/schema"
  5. )
  6. var schema = NewDecoder()
  7. type Validator interface {
  8. Validate() error
  9. }
  10. // Parse parsed the raw query from the URL and updates request.Form,
  11. // decode the from to the given struct with Validator implemented.
  12. func parse(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. }