-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_binding_form.go
46 lines (35 loc) · 1020 Bytes
/
context_binding_form.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// see: https://github.com/gin-gonic/gin/blob/master/binding/form.go
package chain
import (
"errors"
"net/http"
)
const defaultMemory = 32 << 20
type formBinding struct{}
func (formBinding) Bind(ctx *Context, obj any) error {
req := ctx.Request
if err := req.ParseForm(); err != nil {
return err
}
if err := req.ParseMultipartForm(defaultMemory); err != nil && !errors.Is(err, http.ErrNotMultipart) {
return err
}
return mapFormByTag(obj, req.Form, "form")
}
type formPostBinding struct{}
func (formPostBinding) Bind(ctx *Context, obj any) error {
req := ctx.Request
if err := req.ParseForm(); err != nil {
return err
}
return mapFormByTag(obj, req.PostForm, "form")
}
type formMultipartBinding struct{}
func (formMultipartBinding) Bind(ctx *Context, obj any) error {
req := ctx.Request
if err := req.ParseMultipartForm(defaultMemory); err != nil {
return err
}
return mappingByPtr(obj, (*multipartRequest)(req), "form")
}