form_multipart.go 593 B

12345678910111213141516171819202122232425
  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. const MAX_MEMORY = 1 * 1024 * 1024
  7. type multipartFormBinding struct{}
  8. func (_ multipartFormBinding) Name() string {
  9. return "multipart form"
  10. }
  11. func (_ multipartFormBinding) Bind(req *http.Request, obj interface{}) error {
  12. if err := req.ParseMultipartForm(MAX_MEMORY); err != nil {
  13. return err
  14. }
  15. if err := mapForm(obj, req.Form); err != nil {
  16. return err
  17. }
  18. return Validate(obj)
  19. }