rules

package
v0.0.0-...-90e7e3f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

View Source
var (
	ErrMustExistFieldNotExist = errors.New("field doesn't exists")
	ErrMustExistAbsent        = errors.New("field must be present")
)

define errors for the Must Exist Rule

View Source
var (
	ErrInvalidRegexp = errors.New("invalid regexp")
	ErrRegexMismatch = errors.New("regexp mismatch")
)

define errors for the UseMatches Rule

View Source
var (
	ErrExampleMistmatch = errors.New("example mismatch")
)

define errors for the UseMatches Rule

View Source
var (
	ErrFlagFullStop = errors.New("flag full stop")
)

define errors for the UseMatches Rule

View Source
var ExampleMatchesRule = "EXAMPLE_MATCHES_RULE"
View Source
var LengthRule = "LENGTH_RULE"
View Source
var MustExistRule = "MUST_EXIST_RULE"
View Source
var PunctuationRule = "PUNCTUATION_RULE"
View Source
var UseMatchesRule = "USE_MATCHES_RULE"

Functions

func ExecuteRules

func ExecuteRules(cmd *cobra.Command, validatorConfig *ValidatorConfig) []validator.ValidationError

ExecuteRules executes all the rules provided by validatorConfig

func ExecuteRulesInternal

func ExecuteRulesInternal(cmd *cobra.Command, ruleConfig *RuleConfig, userValidatorConfig *ValidatorConfig) []validator.ValidationError

ExecuteRulesInternal executes all the rules provided by ruleConfig

func ValidatorConfigToRuleConfig

func ValidatorConfigToRuleConfig(validatorConfig *ValidatorConfig, ruleConfig *RuleConfig)

ValidatorConfigToRuleConfig intializes the default config and overrides default with user provided config

Types

type ExampleMatches

type ExampleMatches struct {
	RuleOptions validator.RuleOptions
}

ExampleMatches defines Regexp to be compared

func (*ExampleMatches) Validate

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

func (*Length) Validate

func (l *Length) Validate(cmd *cobra.Command) []validator.ValidationError

Validate is a method of type Rule Interface which returns validation errors

type Limit

type Limit struct {
	Min int `json:"Min"`
	Max int `json:"Max"`
}

Limit defines min, max length of string

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

func (*MustExist) Validate

func (m *MustExist) Validate(cmd *cobra.Command) []validator.ValidationError

Validate is a method of type Rule Interface which returns validation errors

type Punctuation

type Punctuation struct {
	RuleOptions validator.RuleOptions
}

UseMatches defines Regexp to be compared

func (*Punctuation) Validate

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

type UseMatches struct {
	RuleOptions validator.RuleOptions
	Regexp      string `json:"Regexp"`
}

UseMatches defines Regexp to be compared

func (*UseMatches) Validate

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

type ValidatorConfig struct {
	ValidatorOptions `json:"ValidatorOptions"`
	ValidatorRules   `json:"ValidatorRules"`
}

ValidatorConfig is provided to user for overriding default rules

type ValidatorOptions

type ValidatorOptions struct {
	Verbose      bool            `json:"Verbose"`
	SkipCommands map[string]bool `json:"SkipCommands"`
}

ValidatorOptions provide additional configurations to the rules

type ValidatorRules

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL