File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -133,12 +133,22 @@ func Key(key interface{}, rules ...Rule) *KeyRules {
133133 }
134134}
135135
136+ // Deprecated: Use Required instead.
137+ //
136138// Optional configures the rule to ignore the key if missing.
137139func (r * KeyRules ) Optional () * KeyRules {
138140 r .optional = true
139141 return r
140142}
141143
144+ // Required sets whether or not this key is required. If it is optional then you
145+ // can pass false to this function. Not calling this function will default to
146+ // the key being required.
147+ func (r * KeyRules ) Required (required bool ) * KeyRules {
148+ r .optional = ! required
149+ return r
150+ }
151+
142152// getErrorKeyName returns the name that should be used to represent the validation error of a map key.
143153func getErrorKeyName (key interface {}) string {
144154 return fmt .Sprintf ("%v" , key )
You can’t perform that action at this time.
0 commit comments