-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuri.go
44 lines (37 loc) · 1011 Bytes
/
uri.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
package bindator
import (
"reflect"
"github.com/fanesz/bindator/handler"
"github.com/fanesz/bindator/internal"
"github.com/gin-gonic/gin"
)
func BindUri(ctx *gin.Context, req interface{}) (res *internal.ValidateReturn) {
if err := ctx.ShouldBindUri(req); err != nil {
return handler.Response(false, err.Error())
}
res, err := internal.ValidateRequest(&req, "uri")
if err != nil {
return handler.Response(false, err.Error())
}
if res != nil {
return res
}
return handler.Response(true, "")
}
func BindUris(ctx *gin.Context, obj interface{}) (res *internal.ValidateReturn) {
v := reflect.ValueOf(obj).Elem()
for i := 0; i < v.NumField(); i++ {
field := v.Field(i).Addr().Interface()
if err := ctx.ShouldBindUri(field); err != nil {
return handler.Response(false, err.Error())
}
res, err := internal.ValidateRequest(&field, "uri")
if err != nil {
return handler.Response(false, err.Error())
}
if res != nil {
return res
}
}
return handler.Response(true, "")
}