-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.go
45 lines (36 loc) · 962 Bytes
/
validate.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 echo
import (
"gopkg.in/go-playground/validator.v9"
)
type (
// Func accepts a FieldLevel interface for all validation needs. The return
// value should be true when validation succeeds.
Func = validator.Func
// FieldLevel contains all the information and helper functions
// to validate a field
FieldLevel = validator.FieldLevel
// Validator to implement custom echo.Validator
Validator interface {
Validate(i interface{}) error
Register(tag string, fn Func) error
}
validate struct {
v *validator.Validate
}
)
func (v *validate) Validate(i interface{}) error {
return v.v.Struct(i)
}
func (v *validate) Register(tag string, fn Func) error {
return v.v.RegisterValidation(tag, fn)
}
// NewValidator returns custom echo.Validator
func NewValidator() Validator {
return WrapValidator(validator.New())
}
// WrapValidator wraps v9.validator
func WrapValidator(v *validator.Validate) Validator {
return &validate{
v: v,
}
}