form.go 544 B

123456789101112131415161718192021222324
  1. // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package binding
  5. import "net/http"
  6. type formBinding struct{}
  7. func (_ formBinding) Name() string {
  8. return "form"
  9. }
  10. func (_ formBinding) Bind(req *http.Request, obj interface{}) error {
  11. if err := req.ParseForm(); err != nil {
  12. return err
  13. }
  14. req.ParseMultipartForm(32 << 10) // 32 MB
  15. if err := mapForm(obj, req.Form); err != nil {
  16. return err
  17. }
  18. return validate(obj)
  19. }