rules

package
v0.0.0-...-3483356 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrValueNotAllowed     = "value-not-allowed"
	ErrRequiredSuffix      = "required-suffix"
	ErrBadFormat           = "bad-format"
	ErrNoMatchRegex        = "not-match-regex"
	ErrZeroOrOneValue      = "zero-or-one-value"
	ErrOneRequired         = "one-required"
	ErrConditionNotMatched = "condition-not-matched"
)

Variables

View Source
var (
	ErrInvalidPartLen  = errors.New("invalid parts length")
	ErrEmptyOpts       = errors.New("no options after separator")
	ErrNoRemainingOpts = errors.New("no remaining options after separator")
	ErrInvalidOptions  = errors.New("invalid options")
)

Functions

func AllowedValues

func AllowedValues(allowedValues ...string) V.Rule

func CanReference

func CanReference(unitTypes ...UnitType) V.Rule

func CheckRules

func CheckRules(validator V.Validator, unit UnitFile, rules model.Groups) []V.ValidationError

func ConflictsWith

func ConflictsWith(others ...Field) V.Rule

func DependsOn

func DependsOn(dependency Field) V.Rule

func Deprecated

func Deprecated(validator V.Validator, unit UnitFile, field Field) []V.ValidationError

func HasSuffix

func HasSuffix(suffix string) V.Rule

func HaveFormat

func HaveFormat(format Format) V.Rule

func HaveZeroOrOneValues

func HaveZeroOrOneValues(validator V.Validator, field Field, values []UnitValue) *V.ValidationError

func MatchRegexp

func MatchRegexp(regex *regexp.Regexp) V.Rule

func RequiredIfNotPresent

func RequiredIfNotPresent(other Field) V.Rule

func Rules

func Rules(rules ...V.Rule) []V.Rule

func ValuesMust

func ValuesMust(valuesPredicate ValuesValidator, rulePredicate RulePredicate, messageAndArgs ...any) V.Rule

Types

type Format

type Format struct {
	Name             string // Name of the Format
	ValueSeparator   string // ValueSeparator is the separator between the value and its options
	OptionsSeparator string // OptionsSeparator is the separator between the options

	ValidateOptions func(value string, options map[string]string) error
}

Format is the format that a value of a given key has For example: the Network key has the format: mode[:options,...] so the Format would be: - ValueSeparator: ":" - OptionsSeparator: ","

func (*Format) ParseAndValidate

func (f *Format) ParseAndValidate(value string) (FormatValidationResult, error)

type FormatValidationResult

type FormatValidationResult struct {
	Value string // Value is the value before the ValueSeparator. Populated after calling ParseAndValidate.
	// Options are the options after the ValueSeparator split by the OptionsSeparator.
	// Populated after calling ParseAndValidate.
	Options map[string]string
}

type RulePredicate

type RulePredicate func(validator V.Validator, unit UnitFile, field Field) bool

func WhenFieldEquals

func WhenFieldEquals(conditionField Field, conditionValues ...string) RulePredicate

type ValuesValidator

type ValuesValidator func(validator V.Validator, field Field, values []UnitValue) *V.ValidationError

Jump to

Keyboard shortcuts

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