improve custom validation rule feature for package gvalid
package gvalid
-import (
- "fmt"
-)
-
// RuleFunc is the custom function for data validation.
// The parameter <value> specifies the value for this rule to validate.
// The parameter <message> specifies the custom error message or configured i18n message for this rule.
@@ -25,10 +21,11 @@ var (
// RegisterRule registers custom validation rule and function for package.
// It returns error if there's already the same rule registered previously.
func RegisterRule(rule string, f RuleFunc) error {
- if _, ok := allSupportedRules[rule]; ok {
- return fmt.Errorf(`validation rule "%s" is already registered`, rule)
- }
- allSupportedRules[rule] = struct{}{}
customRuleFuncMap[rule] = f
return nil
}
+
+// DeleteRule deletes custom defined validation rule and its function from global package.
+func DeleteRule(rule string) {
+ delete(customRuleFuncMap, rule)
+}
