-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.go
60 lines (38 loc) · 1.41 KB
/
doc.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
60
/*
Each Validator have at least two process methods, one for 'Parsing' and one for 'Validating'.
In 'Parsing' stage, we call validator as 'ValidatorCreator', and it will be register to some 'ValidatorMgr' for caching.
Parsing
There are common 'Rule DSL' below:
// simple
@name
// with parameters
@name<param1>
@name<param1,param2>
// with ranges
@name[from, to)
@name[length]
// with values
@name{VALUE1,VALUE2,VALUE3}
@name{%v}
// with regexp
@name/\d+/
// optional and default value
@name?
@name = value
@name = 'some string value'
// composes
@map<@string[1,10],@string{A,B,C}>
@map<@string[1,10],@string/\d+/>[0,10]
Then the parsed rule will be transform to special validators:
@string: https://godoc.org/github.com/go-courier/validator#StringValidator
@uint: https://godoc.org/github.com/go-courier/validator#UintValidator
@int: https://godoc.org/github.com/go-courier/validator#IntValidator
@float: https://godoc.org/github.com/go-courier/validator#FloatValidator
@struct: https://godoc.org/github.com/go-courier/validator#StructValidator
@map: https://godoc.org/github.com/go-courier/validator#MapValidator
@slice: https://godoc.org/github.com/go-courier/validator#SliceValidator
Validating
We can create validator by 'Rule DSL', and also can configure them by validator struct field as conditions.
Then call the method `Validate(v interface{}) error` to do value validations.
*/
package validator