validators

package
v0.0.0-...-bb2a316 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HasToBeGreaterThan                = "must be greater than"
	HasToBeLessThan                   = "must be less than"
	HasToBeGreaterOrEqualThen         = "must be greater or equal then"
	HasToBeGreaterThanZero            = "must be greater than 0"
	MustNotBeEmpty                    = "must not be empty"
	MustBeDefined                     = "must be defined"
	MustBeSet                         = "must be set"
	MustNotBeSet                      = "must not be set"
	MustNotBeDefined                  = "must not be defined"
	MustBeDefinedAndGreaterThanZero   = "must be defined and greater than zero"
	WhenDefinedHasToBeNonNegative     = "must not be negative when defined"
	WhenDefinedHasToBeGreaterThanZero = "must be greater than zero when defined"
	HasToBeInRangeFormat              = "must be in inclusive range [%v, %v]"
	WhenDefinedHasToBeValidPath       = "must be a valid path when defined"
	StringHasToBeValidNumber          = "string must be a valid number"
	MustHaveBPSUnit                   = "must be in kbps/Mbps/Gbps units"
)

Variables

View Source
var (
	HasToBeInPercentageRange     = fmt.Sprintf(HasToBeInRangeFormat, "0.0", "100.0")
	HasToBeInUintPercentageRange = fmt.Sprintf(HasToBeInRangeFormat, 0, 100)
)
View Source
var BandwidthRegex = regexp.MustCompile(`(\d*)\s?([GMk]?bps)`)

Functions

func IsValidationError

func IsValidationError(err error) bool

func MustHaveAtLeastOne

func MustHaveAtLeastOne(allowedValues ...string) string

func MustHaveExactlyOneOf

func MustHaveExactlyOneOf(entity string, allowedValues ...string) string

func MustHaveOnlyOne

func MustHaveOnlyOne(entity string, allowedValues ...string) string

Types

type PathBuilder

type PathBuilder []string

func Root

func Root() PathBuilder

func RootedAt

func RootedAt(name string) PathBuilder

func (PathBuilder) Field

func (p PathBuilder) Field(name string) PathBuilder

func (PathBuilder) Index

func (p PathBuilder) Index(index int) PathBuilder

func (PathBuilder) Key

func (p PathBuilder) Key(key string) PathBuilder

func (PathBuilder) String

func (p PathBuilder) String() string

type ValidationError

type ValidationError struct {
	Violations []Violation `json:"violations"`
}

func MakeFieldMustBeOneOfErr

func MakeFieldMustBeOneOfErr(field string, allowed ...string) ValidationError

func MakeOneOfErr

func MakeOneOfErr(fieldA, fieldB, msg string, oneOf []string) ValidationError

func MakeRequiredFieldErr

func MakeRequiredFieldErr(path PathBuilder) ValidationError

func MakeUnimplementedFieldErr

func MakeUnimplementedFieldErr(path PathBuilder) ValidationError

func OK

func OK() ValidationError

OK returns and empty validation error (i.e. success).

func ValidateBandwidth

func ValidateBandwidth(path PathBuilder, value string) ValidationError

func ValidateDurationGreaterThan

func ValidateDurationGreaterThan(path PathBuilder, duration *k8s.Duration, minDuration time.Duration) ValidationError

func ValidateDurationGreaterThanZero

func ValidateDurationGreaterThanZero(path PathBuilder, duration k8s.Duration) ValidationError

func ValidateDurationGreaterThanZeroOrNil

func ValidateDurationGreaterThanZeroOrNil(path PathBuilder, duration *k8s.Duration) ValidationError

func ValidateDurationNotNegative

func ValidateDurationNotNegative(path PathBuilder, duration *k8s.Duration) ValidationError

func ValidateDurationNotNegativeOrNil

func ValidateDurationNotNegativeOrNil(path PathBuilder, duration *k8s.Duration) ValidationError

func ValidateIntPercentageOrNil

func ValidateIntPercentageOrNil(path PathBuilder, percentage *int32) ValidationError

func ValidateIntegerGreaterThan

func ValidateIntegerGreaterThan(path PathBuilder, value uint32, minValue uint32) ValidationError

func ValidateIntegerGreaterThanZeroOrNil

func ValidateIntegerGreaterThanZeroOrNil(path PathBuilder, value *uint32) ValidationError

func ValidateNil

func ValidateNil[T any](path PathBuilder, t *T, msg string) ValidationError

func ValidatePathOrNil

func ValidatePathOrNil(path PathBuilder, filePath *string) ValidationError

func ValidatePort

func ValidatePort(path PathBuilder, value uint32) ValidationError

func ValidateStatusCode

func ValidateStatusCode(path PathBuilder, status int32) ValidationError

func ValidateStringDefined

func ValidateStringDefined(path PathBuilder, value string) ValidationError

func ValidateUInt32PercentageOrNil

func ValidateUInt32PercentageOrNil(path PathBuilder, percentage *uint32) ValidationError

func ValidateValueGreaterThanZero

func ValidateValueGreaterThanZero(path PathBuilder, value int32) ValidationError

func ValidateValueGreaterThanZeroOrNil

func ValidateValueGreaterThanZeroOrNil(path PathBuilder, value *int32) ValidationError

func (*ValidationError) Add

func (v *ValidationError) Add(err ValidationError)

func (*ValidationError) AddError

func (v *ValidationError) AddError(rootField string, validationErr ValidationError)

func (*ValidationError) AddErrorAt

func (v *ValidationError) AddErrorAt(path PathBuilder, validationErr ValidationError)

func (*ValidationError) AddViolation

func (v *ValidationError) AddViolation(field string, message string)

func (*ValidationError) AddViolationAt

func (v *ValidationError) AddViolationAt(path PathBuilder, message string)

func (*ValidationError) Error

func (v *ValidationError) Error() string

func (*ValidationError) HasViolations

func (v *ValidationError) HasViolations() bool

func (*ValidationError) OrNil

func (v *ValidationError) OrNil() error

func (*ValidationError) Transform

func (v *ValidationError) Transform(transformFunc func(Violation) Violation) *ValidationError

Transform returns a new ValidationError with every violation transformed by a given transformFunc.

type Violation

type Violation struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

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