File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ and has the ability to dive into arrays and maps of any type.
7
7
8
8
see more examples https://github.com/go-playground/validator/tree/master/_examples
9
9
10
+ Singleton
11
+
12
+ Validator is designed to be thread-safe and used as a singleton instance.
13
+ It caches information about your struct and validations,
14
+ in essence only parsing your validation tags once per struct type.
15
+ Using multiple instances neglects the benefit of caching.
16
+ The not thread-safe functions are explicitly marked as such in the documentation.
17
+
10
18
Validation Functions Return Type error
11
19
12
20
Doing things this way is actually the way the standard library does, see the
Original file line number Diff line number Diff line change @@ -89,6 +89,10 @@ type Validate struct {
89
89
}
90
90
91
91
// New returns a new instance of 'validate' with sane defaults.
92
+ // Validate is designed to be thread-safe and used as a singleton instance.
93
+ // It caches information about your struct and validations,
94
+ // in essence only parsing your validation tags once per struct type.
95
+ // Using multiple instances neglects the benefit of caching.
92
96
func New () * Validate {
93
97
94
98
tc := new (tagCache )
You can’t perform that action at this time.
0 commit comments