Documentation ¶
Index ¶
- Constants
- Variables
- func IsValidationError(err error) bool
- func MustHaveAtLeastOne(allowedValues ...string) string
- func MustHaveExactlyOneOf(entity string, allowedValues ...string) string
- func MustHaveOnlyOne(entity string, allowedValues ...string) string
- type PathBuilder
- type ValidationError
- func MakeFieldMustBeOneOfErr(field string, allowed ...string) ValidationError
- func MakeOneOfErr(fieldA, fieldB, msg string, oneOf []string) ValidationError
- func MakeRequiredFieldErr(path PathBuilder) ValidationError
- func MakeUnimplementedFieldErr(path PathBuilder) ValidationError
- func OK() ValidationError
- func ValidateBandwidth(path PathBuilder, value string) ValidationError
- func ValidateDurationGreaterThan(path PathBuilder, duration *k8s.Duration, minDuration time.Duration) ValidationError
- func ValidateDurationGreaterThanZero(path PathBuilder, duration k8s.Duration) ValidationError
- func ValidateDurationGreaterThanZeroOrNil(path PathBuilder, duration *k8s.Duration) ValidationError
- func ValidateDurationNotNegative(path PathBuilder, duration *k8s.Duration) ValidationError
- func ValidateDurationNotNegativeOrNil(path PathBuilder, duration *k8s.Duration) ValidationError
- func ValidateIntPercentageOrNil(path PathBuilder, percentage *int32) ValidationError
- func ValidateIntegerGreaterThan(path PathBuilder, value uint32, minValue uint32) ValidationError
- func ValidateIntegerGreaterThanZeroOrNil(path PathBuilder, value *uint32) ValidationError
- func ValidateNil[T any](path PathBuilder, t *T, msg string) ValidationError
- func ValidatePathOrNil(path PathBuilder, filePath *string) ValidationError
- func ValidatePort(path PathBuilder, value uint32) ValidationError
- func ValidateStatusCode(path PathBuilder, status int32) ValidationError
- func ValidateStringDefined(path PathBuilder, value string) ValidationError
- func ValidateUInt32PercentageOrNil(path PathBuilder, percentage *uint32) ValidationError
- func ValidateValueGreaterThanZero(path PathBuilder, value int32) ValidationError
- func ValidateValueGreaterThanZeroOrNil(path PathBuilder, value *int32) ValidationError
- func (v *ValidationError) Add(err ValidationError)
- func (v *ValidationError) AddError(rootField string, validationErr ValidationError)
- func (v *ValidationError) AddErrorAt(path PathBuilder, validationErr ValidationError)
- func (v *ValidationError) AddViolation(field string, message string)
- func (v *ValidationError) AddViolationAt(path PathBuilder, message string)
- func (v *ValidationError) Error() string
- func (v *ValidationError) HasViolations() bool
- func (v *ValidationError) OrNil() error
- func (v *ValidationError) Transform(transformFunc func(Violation) Violation) *ValidationError
- type Violation
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 MustHaveAtLeastOne ¶
func MustHaveExactlyOneOf ¶
func MustHaveOnlyOne ¶
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 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.
Click to show internal directories.
Click to hide internal directories.