-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.go
45 lines (36 loc) · 1.1 KB
/
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
package binding
import (
"github.com/gofiber/fiber/v3"
"github.com/hopeio/cherry/utils/net/http/binding"
binding2 "github.com/hopeio/cherry/utils/net/http/fasthttp/binding"
)
type formBinding struct{}
type formPostBinding struct{}
type formMultipartBinding struct{}
func (formMultipartBinding) Name() string {
return "multipart/form-data"
}
func (formMultipartBinding) Bind(ctx fiber.Ctx, obj interface{}) error {
if err := binding.MappingByPtr(obj, (*binding2.MultipartRequest)(ctx.Request()), binding.Tag); err != nil {
return err
}
return binding.Validate(obj)
}
func (formBinding) Name() string {
return "form"
}
func (formBinding) Bind(ctx fiber.Ctx, obj interface{}) error {
if err := binding.MapForm(obj, (*binding2.ArgsSource)(ctx.Request().PostArgs())); err != nil {
return err
}
return binding.Validate(obj)
}
func (formPostBinding) Name() string {
return "form-urlencoded"
}
func (formPostBinding) Bind(ctx fiber.Ctx, obj interface{}) error {
if err := binding.MapForm(obj, (*binding2.ArgsSource)(ctx.Request().PostArgs())); err != nil {
return err
}
return binding.Validate(obj)
}