This repository was archived by the owner on Dec 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-7
lines changed
Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,10 @@ package validator_test
2222import (
2323 " fmt"
2424
25- " github.com/bytedance/go-tagexpr/validator"
25+ vd " github.com/bytedance/go-tagexpr/validator"
2626)
2727
2828func Example () {
29- var vd = validator.New (" vd" )
30-
3129 type InfoRequest struct {
3230 Name string ` vd:"($!='Alice'||(Age)$==18) && regexp('\\w')"`
3331 Age int ` vd:"$>0"`
@@ -93,7 +91,7 @@ func Example() {
9391
9492 fmt.Println (vd.Validate (map [string ]*F{" a" : f}))
9593
96- fmt.Println (vd.Validate ([]*F{f }))
94+ fmt.Println (vd.Validate ([][ 1 ] *F{{f} }))
9795
9896 f = nil
9997 fmt.Println (vd.Validate (f))
Original file line number Diff line number Diff line change 1+ package validator
2+
3+ var defaultValidator = New ("vd" ).SetErrorFactory (defaultErrorFactory )
4+
5+ // Default returns the default validator.
6+ // NOTE:
7+ // The tag name is 'vd'
8+ func Default () * Validator {
9+ return defaultValidator
10+ }
11+
12+ // Validate uses the default validator to validate whether the fields of value is valid.
13+ // NOTE:
14+ // The tag name is 'vd'
15+ func Validate (value interface {}) error {
16+ return defaultValidator .Validate (value )
17+ }
18+
19+ // SetErrorFactory customizes the factory of validation error for the default validator.
20+ // NOTE:
21+ // The tag name is 'vd'
22+ func SetErrorFactory (errFactory func (fieldSelector , msg string ) error ) {
23+ defaultValidator .SetErrorFactory (errFactory )
24+ }
Original file line number Diff line number Diff line change @@ -3,12 +3,10 @@ package validator_test
33import (
44 "fmt"
55
6- "github.com/bytedance/go-tagexpr/validator"
6+ vd "github.com/bytedance/go-tagexpr/validator"
77)
88
99func Example () {
10- var vd = validator .New ("vd" )
11-
1210 type InfoRequest struct {
1311 Name string `vd:"($!='Alice'||(Age)$==18) && regexp('\\w')"`
1412 Age int `vd:"$>0"`
You can’t perform that action at this time.
0 commit comments