Documentation
¶
Index ¶
- Variables
- func ExecuteRules(cmd *cobra.Command, validatorConfig *ValidatorConfig) []validator.ValidationError
- func ExecuteRulesInternal(cmd *cobra.Command, ruleConfig *RuleConfig, ...) []validator.ValidationError
- func ValidatorConfigToRuleConfig(validatorConfig *ValidatorConfig, ruleConfig *RuleConfig)
- type ExampleMatches
- type Length
- type Limit
- type MustExist
- type Punctuation
- type RuleConfig
- type Rules
- type UseMatches
- type ValidatorConfig
- type ValidatorOptions
- type ValidatorRules
Constants ¶
This section is empty.
Variables ¶
var ( ErrLengthMin = errors.New("less than min") ErrLengthMax = errors.New("less than max") ErrLengthInvalid = errors.New("invalid length") ErrLengthNegative = errors.New("negative value") ErrLengthZeroValue = errors.New("zero value") ErrLengthFieldNotExist = errors.New("field doesn't exists") )
define errors for the Length Rule
var ( ErrMustExistFieldNotExist = errors.New("field doesn't exists") ErrMustExistAbsent = errors.New("field must be present") )
define errors for the Must Exist Rule
var ( ErrInvalidRegexp = errors.New("invalid regexp") ErrRegexMismatch = errors.New("regexp mismatch") )
define errors for the UseMatches Rule
var (
ErrExampleMistmatch = errors.New("example mismatch")
)
define errors for the UseMatches Rule
var (
ErrFlagFullStop = errors.New("flag full stop")
)
define errors for the UseMatches Rule
var ExampleMatchesRule = "EXAMPLE_MATCHES_RULE"
var LengthRule = "LENGTH_RULE"
var MustExistRule = "MUST_EXIST_RULE"
var PunctuationRule = "PUNCTUATION_RULE"
var UseMatchesRule = "USE_MATCHES_RULE"
Functions ¶
func ExecuteRules ¶ added in v0.2.0
func ExecuteRules(cmd *cobra.Command, validatorConfig *ValidatorConfig) []validator.ValidationError
ExecuteRules executes all the rules provided by validatorConfig
func ExecuteRulesInternal ¶ added in v0.2.0
func ExecuteRulesInternal(cmd *cobra.Command, ruleConfig *RuleConfig, userValidatorConfig *ValidatorConfig) []validator.ValidationError
ExecuteRulesInternal executes all the rules provided by ruleConfig
func ValidatorConfigToRuleConfig ¶ added in v0.2.0
func ValidatorConfigToRuleConfig(validatorConfig *ValidatorConfig, ruleConfig *RuleConfig)
ValidatorConfigToRuleConfig intializes the default config and overrides default with user provided config
Types ¶
type ExampleMatches ¶ added in v0.3.0
type ExampleMatches struct {
RuleOptions validator.RuleOptions
}
ExampleMatches defines Regexp to be compared
func (*ExampleMatches) Validate ¶ added in v0.3.0
func (e *ExampleMatches) Validate(cmd *cobra.Command) []validator.ValidationError
Validate is a method of type Rule Interface which returns validation errors checks if the example is updated as per command
type Length ¶
type Length struct {
RuleOptions validator.RuleOptions
Limits map[string]Limit `json:"Limits"`
}
Length is a struct that provides a map with key as attribute for which length is controlled and value limit as Limit struct
type MustExist ¶
type MustExist struct {
RuleOptions validator.RuleOptions
Fields map[string]bool `json:"Fields"`
}
MustExist is a struct that provides Fields defined for MustExist validation
type Punctuation ¶ added in v0.6.1
type Punctuation struct {
RuleOptions validator.RuleOptions
}
UseMatches defines Regexp to be compared
func (*Punctuation) Validate ¶ added in v0.6.1
func (p *Punctuation) Validate(cmd *cobra.Command) []validator.ValidationError
Validate is a method of type Rule Interface which returns validation errors
type RuleConfig ¶
type RuleConfig struct {
Rules []Rules
}
RuleConfig is the struct that stores configuration of rules
type Rules ¶
type Rules interface {
Validate(cmd *cobra.Command) []validator.ValidationError
}
Rules is an interface that is implemented by every rule defined in rules package
type UseMatches ¶ added in v0.2.0
type UseMatches struct {
RuleOptions validator.RuleOptions
Regexp string `json:"Regexp"`
}
UseMatches defines Regexp to be compared
func (*UseMatches) Validate ¶ added in v0.2.0
func (u *UseMatches) Validate(cmd *cobra.Command) []validator.ValidationError
Validate is a method of type Rule Interface which returns validation errors compares the regexp with Use attribute
type ValidatorConfig ¶ added in v0.2.0
type ValidatorConfig struct {
ValidatorOptions `json:"ValidatorOptions"`
ValidatorRules `json:"ValidatorRules"`
}
ValidatorConfig is provided to user for overriding default rules
type ValidatorOptions ¶ added in v0.2.0
type ValidatorOptions struct {
Verbose bool `json:"Verbose"`
SkipCommands map[string]bool `json:"SkipCommands"`
}
ValidatorOptions provide additional configurations to the rules
type ValidatorRules ¶ added in v0.2.0
type ValidatorRules struct {
Length `json:"Length"`
MustExist `json:"MustExist"`
UseMatches `json:"UseMatches"`
ExampleMatches `json:"ExampleMatches"`
Punctuation `json:"Punctuation"`
}
ValidatorRules consists of all the rules present in validator