Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrPath = va.NewError("valid_is_path", "must be a valid file path") ErrExtension = va.NewError("valid_is_extension", "must be formatted like \".gz\" or \".tar.gz\"") ErrEmptyString = va.NewError("valid_is_empty_string", "must be empty") ErrExistingFile = va.NewError("valid_is_existing_file", "file does not exist") ErrExistingDir = va.NewError("valid_is_existing_dir", "directory does not exist") ErrZero = va.NewError("valid_is_zero", "must be empty") ErrBeforeTimeParam = va.NewError("valid_before_time_param", "must not come before {{.param}}") ErrPathNotWithinParam = va.NewError("valid_not_within_dir", "must not be within {{.param}}") ErrRegexpPattern = va.NewError("valid_regex", "must be a valid regular expression") )
View Source
var EmptyString = va.NewStringRuleWithError(func(s string) bool { return s == "" }, ErrEmptyString)
View Source
var ExistingDir = va.NewStringRuleWithError(func(value string) bool { fileInfo, err := os.Stat(value) return !os.IsNotExist(err) && fileInfo.Mode().IsDir() }, ErrExistingDir)
View Source
var ExistingFile = va.NewStringRuleWithError(func(value string) bool { fileInfo, err := os.Stat(value) return !os.IsNotExist(err) && fileInfo.Mode().IsRegular() }, ErrExistingFile)
View Source
var Extension = va.NewStringRuleWithError(func(s string) bool { return s == "" || (strings.HasPrefix(s, ".") && !strings.HasSuffix(s, ".")) }, ErrExtension)
View Source
var Path = va.NewStringRuleWithError(func(value string) (result bool) { result, _ = govalidator.IsFilePath(value) return }, ErrPath)
View Source
var RegexpPattern = va.By(func(value interface{}) (err error) { input := value.(string) if input == "" { return } if _, err := regexp.Compile(input); err != nil { vaErr := ErrRegexpPattern msg := fmt.Sprintf(`%s (rule: %s; error: %s)`, vaErr.Message(), input, err.Error()) return vaErr.SetMessage(msg) } return })
View Source
var RegexpTmpl = va.By(func(value interface{}) (err error) { input := value.(string) if input == "" { return } replacer := regexp.MustCompile(`{{[^}]+}}`) pattern := replacer.ReplaceAllString(input, `TMPL_REF_PLACEHOLDER`) return RegexpPattern.Validate(pattern) })
View Source
var Zero = newRuleWithError(IsZero, ErrZero)
Functions ¶
Types ¶
type IsBeforeTimeParamRule ¶
type IsBeforeTimeParamRule struct{}
type IsPathNotWithinParamRule ¶
type IsPathNotWithinParamRule struct {
// contains filtered or unexported fields
}
func PathNotWithinParam ¶
func PathNotWithinParam(param *manip.Param) IsPathNotWithinParamRule
func (IsPathNotWithinParamRule) Param ¶
func (r IsPathNotWithinParamRule) Param() *manip.Param
func (IsPathNotWithinParamRule) Validate ¶
func (r IsPathNotWithinParamRule) Validate(value interface{}) (err error)
type ParamRule ¶
type ParamRule struct {
// contains filtered or unexported fields
}
func BeforeTime ¶
func NewParamRule ¶
type WhenBothNotZeroRule ¶
type WhenBothNotZeroRule struct {
// contains filtered or unexported fields
}
func WhenBothNotZero ¶
func WhenBothNotZero(rules ...ParamRule) WhenBothNotZeroRule
func (WhenBothNotZeroRule) Validate ¶
func (r WhenBothNotZeroRule) Validate(value interface{}) error
func (WhenBothNotZeroRule) ValidateWithContext ¶
func (r WhenBothNotZeroRule) ValidateWithContext(ctx context.Context, value interface{}) error
Click to show internal directories.
Click to hide internal directories.