-
Notifications
You must be signed in to change notification settings - Fork 3
/
validateStruct.go
59 lines (50 loc) · 1.35 KB
/
validateStruct.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package validateKit
import (
"context"
"github.com/go-playground/validator/v10"
)
// Struct 验证结构体.
/*
@param s 如果为nil,将返回error(e.g. validator: (nil *main.User))
*/
func Struct(s interface{}) error {
v := New()
return v.Struct(s)
}
func StructCtx(ctx context.Context, s interface{}) error {
v := New()
return v.StructCtx(ctx, s)
}
// StructExcept 验证结构体,排除指定的字段.
/*
@param fields 支持嵌套
*/
func StructExcept(s interface{}, fields ...string) error {
v := New()
return v.StructExcept(s, fields...)
}
func StructExceptCtx(ctx context.Context, s interface{}, fields ...string) error {
v := New()
return v.StructExceptCtx(ctx, s, fields...)
}
// StructPartial 验证结构体,只验证指定的字段.
/*
@param fields 支持嵌套
*/
func StructPartial(s interface{}, fields ...string) error {
v := New()
return v.StructPartial(s, fields...)
}
func StructPartialCtx(ctx context.Context, s interface{}, fields ...string) error {
v := New()
return v.StructPartialCtx(ctx, s, fields...)
}
// StructFiltered 验证结构体,过滤指定的字段.
func StructFiltered(s interface{}, fn validator.FilterFunc) error {
v := New()
return v.StructFiltered(s, fn)
}
func StructFilteredCtx(ctx context.Context, s interface{}, fn validator.FilterFunc) error {
v := New()
return v.StructFilteredCtx(ctx, s, fn)
}