Documentation
¶
Overview ¶
Package govalid provides composable, type-aware validation rules for selected fields of Go structs.
Validation is explicit: callers associate field paths with rules through Field and execute them with a Validator. Rules cover strings, booleans, integers, floating-point numbers, bytes, maps, collections, universal value states, and conditional composition. Consumers can also implement custom rules with RuleContext and plug alternate field-declaration mechanisms into Validator with FieldSource.
Index ¶
- type Condition
- type FieldIssueError
- type FieldSource
- type FieldSourceFunc
- type FieldSpec
- type Issue
- type Option
- type Rule
- func BoolEqual(expect bool) Rule
- func BoolFalse() Rule
- func BoolTrue() Rule
- func Bytes() Rule
- func BytesASCII() Rule
- func BytesAllZero() Rule
- func BytesAt(index int, rules ...Rule) Rule
- func BytesAtIfPresent(index int, rules ...Rule) Rule
- func BytesBase64() Rule
- func BytesBase64URL() Rule
- func BytesBetween(minimum, maximum []byte) Rule
- func BytesConstantTimeEqual(expected []byte) Rule
- func BytesContains(expected []byte) Rule
- func BytesContainsAll(expected ...[]byte) Rule
- func BytesContainsAny(expected ...[]byte) Rule
- func BytesEach(rules ...Rule) Rule
- func BytesEmpty() Rule
- func BytesEqual(expected []byte) Rule
- func BytesGreaterThan(expected []byte) Rule
- func BytesGreaterThanOrEqual(expected []byte) Rule
- func BytesHasPrefix(prefix []byte) Rule
- func BytesHasSuffix(suffix []byte) Rule
- func BytesHasZero() Rule
- func BytesHex() Rule
- func BytesJSON() Rule
- func BytesLength(expect int) Rule
- func BytesLengthBetween(minimum, maximum int) Rule
- func BytesLengthNotBetween(minimum, maximum int) Rule
- func BytesLessThan(expected []byte) Rule
- func BytesLessThanOrEqual(expected []byte) Rule
- func BytesMaxLength(expect int) Rule
- func BytesMinLength(expect int) Rule
- func BytesNil() Rule
- func BytesNoZero() Rule
- func BytesNoneOf(unexpected ...[]byte) Rule
- func BytesNotAllZero() Rule
- func BytesNotContains(unexpected []byte) Rule
- func BytesNotEmpty() Rule
- func BytesNotEqual(unexpected []byte) Rule
- func BytesNotHasPrefix(prefix []byte) Rule
- func BytesNotHasSuffix(suffix []byte) Rule
- func BytesNotNil() Rule
- func BytesNotUTF8() Rule
- func BytesOneOf(expected ...[]byte) Rule
- func BytesPEM() Rule
- func BytesPrintableASCII() Rule
- func BytesUTF8() Rule
- func BytesUnique() Rule
- func BytesXML() Rule
- func Collection() Rule
- func CollectionAny(rules ...Rule) Rule
- func CollectionContains[T any](expected T) Rule
- func CollectionContainsAll[T any](expected ...T) Rule
- func CollectionContainsAny[T any](expected ...T) Rule
- func CollectionEach(rules ...Rule) Rule
- func CollectionEmpty() Rule
- func CollectionEqual[T any](expected T) Rule
- func CollectionHasNonZeroItem() Rule
- func CollectionItemAt(index int, rules ...Rule) Rule
- func CollectionItemAtIfPresent(index int, rules ...Rule) Rule
- func CollectionLength(expect int) Rule
- func CollectionLengthBetween(minimum, maximum int) Rule
- func CollectionLengthNotBetween(minimum, maximum int) Rule
- func CollectionMaxLength(expect int) Rule
- func CollectionMinLength(expect int) Rule
- func CollectionNil() Rule
- func CollectionNoNilItems() Rule
- func CollectionNoZeroItems() Rule
- func CollectionNone(rules ...Rule) Rule
- func CollectionNotContains[T any](unexpected T) Rule
- func CollectionNotEmpty() Rule
- func CollectionNotEqual[T any](unexpected T) Rule
- func CollectionNotNil() Rule
- func CollectionUnique() Rule
- func FloatBetween[Min floating, Max floating](minimum Min, maximum Max) Rule
- func FloatBits(bits int) Rule
- func FloatEqual[T floating](expect T) Rule
- func FloatEqualWithin[T floating](expect T, tolerance float64) Rule
- func FloatFinite() Rule
- func FloatGreaterThan[T floating](expect T) Rule
- func FloatGreaterThanOrEqual[T floating](expect T) Rule
- func FloatInfinite() Rule
- func FloatIs32() Rule
- func FloatIs64() Rule
- func FloatLessThan[T floating](expect T) Rule
- func FloatLessThanOrEqual[T floating](expect T) Rule
- func FloatMax[T floating](expect T) Rule
- func FloatMin[T floating](expect T) Rule
- func FloatNaN() Rule
- func FloatNegative() Rule
- func FloatNegativeInfinite() Rule
- func FloatNonNegative() Rule
- func FloatNonPositive() Rule
- func FloatNonZero() Rule
- func FloatNotBetween[Min floating, Max floating](minimum Min, maximum Max) Rule
- func FloatNotEqual[T floating](expect T) Rule
- func FloatNotFinite() Rule
- func FloatNotInfinite() Rule
- func FloatNotNaN() Rule
- func FloatPositive() Rule
- func FloatPositiveInfinite() Rule
- func FloatZero() Rule
- func IntBetween[Min integer, Max integer](minimum Min, maximum Max) Rule
- func IntCompound() Rule
- func IntDivisibleBy[T integer](n T) Rule
- func IntEqual[T integer](expect T) Rule
- func IntEven() Rule
- func IntGreaterThan[T integer](expect T) Rule
- func IntGreaterThanOrEqual[T integer](expect T) Rule
- func IntHTTPStatus() Rule
- func IntLessThan[T integer](expect T) Rule
- func IntLessThanOrEqual[T integer](expect T) Rule
- func IntMax[T integer](expect T) Rule
- func IntMin[T integer](expect T) Rule
- func IntMultipleOf[T integer](n T) Rule
- func IntNegative() Rule
- func IntNonNegative() Rule
- func IntNonPositive() Rule
- func IntNonZero() Rule
- func IntNoneOf[T integer](restricted ...T) Rule
- func IntNotBetween[Min integer, Max integer](minimum Min, maximum Max) Rule
- func IntNotEqual[T integer](expect T) Rule
- func IntOdd() Rule
- func IntOneOf[T integer](allowed ...T) Rule
- func IntPercentage() Rule
- func IntPerfectSquare() Rule
- func IntPort() Rule
- func IntPositive() Rule
- func IntPowerOfTwo() Rule
- func IntPrime() Rule
- func IntZero() Rule
- func Map() Rule
- func MapAllowedKeys[K comparable](allowed ...K) Rule
- func MapContainsAllValues[V any](expected ...V) Rule
- func MapContainsAnyValue[V any](expected ...V) Rule
- func MapContainsValue[V any](expected V) Rule
- func MapEmpty() Rule
- func MapEqual[M ~map[K]V, K comparable, V any](expected M) Rule
- func MapHasAllKeys[K comparable](expected ...K) Rule
- func MapHasAnyKey[K comparable](expected ...K) Rule
- func MapHasExactKeys[K comparable](expected ...K) Rule
- func MapHasKey[K comparable](expected K) Rule
- func MapHasNonZeroValue() Rule
- func MapHasNoneOfKeys[K comparable](unexpected ...K) Rule
- func MapKeys(rules ...Rule) Rule
- func MapLength(expect int) Rule
- func MapLengthBetween(minimum, maximum int) Rule
- func MapLengthNotBetween(minimum, maximum int) Rule
- func MapMaxLength(expect int) Rule
- func MapMinLength(expect int) Rule
- func MapNil() Rule
- func MapNoNilValues() Rule
- func MapNoZeroValues() Rule
- func MapNotContainsValue[V any](unexpected V) Rule
- func MapNotEmpty() Rule
- func MapNotEqual[M ~map[K]V, K comparable, V any](unexpected M) Rule
- func MapNotHasKey[K comparable](unexpected K) Rule
- func MapNotNil() Rule
- func MapSubsetOf[M ~map[K]V, K comparable, V any](expected M) Rule
- func MapSupersetOf[M ~map[K]V, K comparable, V any](expected M) Rule
- func MapValueAt[K comparable](key K, rules ...Rule) Rule
- func MapValueAtIfPresent[K comparable](key K, rules ...Rule) Rule
- func MapValues(rules ...Rule) Rule
- func Nil() Rule
- func NotNil() Rule
- func NotZero() Rule
- func Optional(rules ...Rule) Rule
- func Required() Rule
- func StringASCII() Rule
- func StringAlpha() Rule
- func StringAlphaNumeric() Rule
- func StringContains(expect string) Rule
- func StringContainsFold(expect string) Rule
- func StringEmail() Rule
- func StringEndsWith(expect string) Rule
- func StringEndsWithFold(expect string) Rule
- func StringLength(expect int) Rule
- func StringLowercase() Rule
- func StringMaxLength(expect int) Rule
- func StringMinLength(expect int) Rule
- func StringNotContains(expect string) Rule
- func StringNotContainsFold(expect string) Rule
- func StringNotOneOf(unexpected ...string) Rule
- func StringNumeric() Rule
- func StringOneOf(expected ...string) Rule
- func StringRegex(expression regexp.Regexp) Rule
- func StringRequired() Rule
- func StringStartsWith(expect string) Rule
- func StringStartsWithFold(expect string) Rule
- func StringTrimmed() Rule
- func StringURL() Rule
- func StringUUID() Rule
- func StringUppercase() Rule
- func Unless(condition bool, rules ...Rule) Rule
- func UnlessContext(condition Condition, rules ...Rule) Rule
- func When(condition bool, rules ...Rule) Rule
- func WhenContext(condition Condition, rules ...Rule) Rule
- func Zero() Rule
- type RuleContext
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition func(context RuleContext) bool
Condition decides whether contextual rules should run.
type FieldIssueError ¶
type FieldIssueError struct {
RulesIssues []Issue
}
FieldIssueError contains the issues collected during one validation run.
func (*FieldIssueError) As ¶
func (field *FieldIssueError) As(target any) bool
As lets errors.As extract the first individual Issue from a validation error. Extract FieldIssueError itself to inspect every collected issue.
func (*FieldIssueError) Error ¶
func (field *FieldIssueError) Error() string
Error formats every collected validation issue.
type FieldSource ¶
FieldSource discovers field specifications for a struct type. It allows alternate declaration mechanisms, such as a future struct-tag parser, to reuse Validator without changing its execution API.
Implementations used concurrently must be concurrency-safe.
type FieldSourceFunc ¶
FieldSourceFunc adapts a function to FieldSource.
type FieldSpec ¶
FieldSpec associates a struct field path with validation rules.
func FieldIfPresent ¶
FieldIfPresent associates rules with a field path but skips them when an intermediate pointer or interface in that path is nil. The selected field itself is still validated when its parent path exists.
type Option ¶
type Option func(opts *options)
Option configures a Validator during construction.
func WithFieldSources ¶
func WithFieldSources(sources ...FieldSource) Option
WithFieldSources registers field-discovery extensions that run before the explicit FieldSpec values passed to Validate. Sources are copied during construction and must be concurrency-safe when the Validator is shared.
func WithIssueHandler ¶
WithIssueHandler registers a callback invoked once for every failed rule. The handler runs before stop, panic, and silence behavior is applied. A handler used by concurrent validations must itself be concurrency-safe.
func WithPanicOnFirstError ¶
func WithPanicOnFirstError() Option
WithPanicOnFirstError makes validation panic with an Issue on the first failed rule.
func WithSilenceErrors ¶
func WithSilenceErrors() Option
WithSilenceErrors makes validation return nil after running applicable rules. Combine it with WithIssueHandler to observe failures.
func WithStopOnFirstError ¶
func WithStopOnFirstError() Option
WithStopOnFirstError makes validation return after the first failed rule.
type Rule ¶
type Rule func(context RuleContext) error
Rule validates the field described by a RuleContext.
func Bytes ¶
func Bytes() Rule
Bytes requires a byte slice or byte array, including defined byte types.
func BytesASCII ¶
func BytesASCII() Rule
BytesASCII returns a byte-sequence validation rule for ascii.
func BytesAllZero ¶
func BytesAllZero() Rule
BytesAllZero returns a byte-sequence validation rule for all zero.
func BytesAtIfPresent ¶
BytesAtIfPresent returns a byte-sequence validation rule for at if present.
func BytesBase64 ¶
func BytesBase64() Rule
BytesBase64 returns a byte-sequence validation rule for base64.
func BytesBase64URL ¶
func BytesBase64URL() Rule
BytesBase64URL returns a byte-sequence validation rule for base64url.
func BytesBetween ¶
BytesBetween returns a byte-sequence validation rule for between.
func BytesConstantTimeEqual ¶
BytesConstantTimeEqual returns a byte-sequence validation rule for constant time equal.
func BytesContains ¶
BytesContains returns a byte-sequence validation rule for contains.
func BytesContainsAll ¶
BytesContainsAll returns a byte-sequence validation rule for contains all.
func BytesContainsAny ¶
BytesContainsAny returns a byte-sequence validation rule for contains any.
func BytesEmpty ¶
func BytesEmpty() Rule
BytesEmpty returns a byte-sequence validation rule for empty.
func BytesEqual ¶
BytesEqual returns a byte-sequence validation rule for equal.
func BytesGreaterThan ¶
BytesGreaterThan returns a byte-sequence validation rule for greater than.
func BytesGreaterThanOrEqual ¶
BytesGreaterThanOrEqual returns a byte-sequence validation rule for greater than or equal.
func BytesHasPrefix ¶
BytesHasPrefix returns a byte-sequence validation rule for has prefix.
func BytesHasSuffix ¶
BytesHasSuffix returns a byte-sequence validation rule for has suffix.
func BytesHasZero ¶
func BytesHasZero() Rule
BytesHasZero returns a byte-sequence validation rule for has zero.
func BytesLength ¶
BytesLength returns a byte-sequence validation rule for length.
func BytesLengthBetween ¶
BytesLengthBetween returns a byte-sequence validation rule for length between.
func BytesLengthNotBetween ¶
BytesLengthNotBetween returns a byte-sequence validation rule for length not between.
func BytesLessThan ¶
BytesLessThan returns a byte-sequence validation rule for less than.
func BytesLessThanOrEqual ¶
BytesLessThanOrEqual returns a byte-sequence validation rule for less than or equal.
func BytesMaxLength ¶
BytesMaxLength returns a byte-sequence validation rule for max length.
func BytesMinLength ¶
BytesMinLength returns a byte-sequence validation rule for min length.
func BytesNoZero ¶
func BytesNoZero() Rule
BytesNoZero returns a byte-sequence validation rule for no zero.
func BytesNoneOf ¶
BytesNoneOf returns a byte-sequence validation rule for none of.
func BytesNotAllZero ¶
func BytesNotAllZero() Rule
BytesNotAllZero returns a byte-sequence validation rule for not all zero.
func BytesNotContains ¶
BytesNotContains returns a byte-sequence validation rule for not contains.
func BytesNotEmpty ¶
func BytesNotEmpty() Rule
BytesNotEmpty returns a byte-sequence validation rule for not empty.
func BytesNotEqual ¶
BytesNotEqual returns a byte-sequence validation rule for not equal.
func BytesNotHasPrefix ¶
BytesNotHasPrefix returns a byte-sequence validation rule for not has prefix.
func BytesNotHasSuffix ¶
BytesNotHasSuffix returns a byte-sequence validation rule for not has suffix.
func BytesNotNil ¶
func BytesNotNil() Rule
BytesNotNil returns a byte-sequence validation rule for not nil.
func BytesNotUTF8 ¶
func BytesNotUTF8() Rule
BytesNotUTF8 returns a byte-sequence validation rule for not utf8.
func BytesOneOf ¶
BytesOneOf returns a byte-sequence validation rule for one of.
func BytesPrintableASCII ¶
func BytesPrintableASCII() Rule
BytesPrintableASCII returns a byte-sequence validation rule for printable ascii.
func BytesUnique ¶
func BytesUnique() Rule
BytesUnique returns a byte-sequence validation rule for unique.
func CollectionAny ¶
CollectionAny returns a collection validation rule for any.
func CollectionContains ¶
CollectionContains returns a collection validation rule for contains.
func CollectionContainsAll ¶
CollectionContainsAll returns a collection validation rule for contains all.
func CollectionContainsAny ¶
CollectionContainsAny returns a collection validation rule for contains any.
func CollectionEach ¶
CollectionEach returns a collection validation rule for each.
func CollectionEmpty ¶
func CollectionEmpty() Rule
CollectionEmpty returns a collection validation rule for empty.
func CollectionEqual ¶
CollectionEqual returns a collection validation rule for equal.
func CollectionHasNonZeroItem ¶
func CollectionHasNonZeroItem() Rule
CollectionHasNonZeroItem returns a collection validation rule for has non zero item.
func CollectionItemAt ¶
CollectionItemAt returns a collection validation rule for item at.
func CollectionItemAtIfPresent ¶
CollectionItemAtIfPresent returns a collection validation rule for item at if present.
func CollectionLength ¶
CollectionLength returns a collection validation rule for length.
func CollectionLengthBetween ¶
CollectionLengthBetween returns a collection validation rule for length between.
func CollectionLengthNotBetween ¶
CollectionLengthNotBetween returns a collection validation rule for length not between.
func CollectionMaxLength ¶
CollectionMaxLength returns a collection validation rule for max length.
func CollectionMinLength ¶
CollectionMinLength returns a collection validation rule for min length.
func CollectionNil ¶
func CollectionNil() Rule
CollectionNil returns a collection validation rule for nil.
func CollectionNoNilItems ¶
func CollectionNoNilItems() Rule
CollectionNoNilItems returns a collection validation rule for no nil items.
func CollectionNoZeroItems ¶
func CollectionNoZeroItems() Rule
CollectionNoZeroItems returns a collection validation rule for no zero items.
func CollectionNone ¶
CollectionNone returns a collection validation rule for none.
func CollectionNotContains ¶
CollectionNotContains returns a collection validation rule for not contains.
func CollectionNotEmpty ¶
func CollectionNotEmpty() Rule
CollectionNotEmpty returns a collection validation rule for not empty.
func CollectionNotEqual ¶
CollectionNotEqual returns a collection validation rule for not equal.
func CollectionNotNil ¶
func CollectionNotNil() Rule
CollectionNotNil returns a collection validation rule for not nil.
func CollectionUnique ¶
func CollectionUnique() Rule
CollectionUnique returns a collection validation rule for unique.
func FloatBetween ¶
func FloatBetween[Min floating, Max floating](minimum Min, maximum Max) Rule
FloatBetween returns a floating-point validation rule for between.
func FloatEqual ¶
func FloatEqual[T floating](expect T) Rule
FloatEqual returns a floating-point validation rule for equal.
func FloatEqualWithin ¶
FloatEqualWithin returns a floating-point validation rule for equal within.
func FloatFinite ¶
func FloatFinite() Rule
FloatFinite returns a floating-point validation rule for finite.
func FloatGreaterThan ¶
func FloatGreaterThan[T floating](expect T) Rule
FloatGreaterThan returns a floating-point validation rule for greater than.
func FloatGreaterThanOrEqual ¶
func FloatGreaterThanOrEqual[T floating](expect T) Rule
FloatGreaterThanOrEqual returns a floating-point validation rule for greater than or equal.
func FloatInfinite ¶
func FloatInfinite() Rule
FloatInfinite returns a floating-point validation rule for infinite.
func FloatLessThan ¶
func FloatLessThan[T floating](expect T) Rule
FloatLessThan returns a floating-point validation rule for less than.
func FloatLessThanOrEqual ¶
func FloatLessThanOrEqual[T floating](expect T) Rule
FloatLessThanOrEqual returns a floating-point validation rule for less than or equal.
func FloatMax ¶
func FloatMax[T floating](expect T) Rule
FloatMax returns a floating-point validation rule for max.
func FloatMin ¶
func FloatMin[T floating](expect T) Rule
FloatMin returns a floating-point validation rule for min.
func FloatNegative ¶
func FloatNegative() Rule
FloatNegative returns a floating-point validation rule for negative.
func FloatNegativeInfinite ¶
func FloatNegativeInfinite() Rule
FloatNegativeInfinite returns a floating-point validation rule for negative infinite.
func FloatNonNegative ¶
func FloatNonNegative() Rule
FloatNonNegative returns a floating-point validation rule for non negative.
func FloatNonPositive ¶
func FloatNonPositive() Rule
FloatNonPositive returns a floating-point validation rule for non positive.
func FloatNonZero ¶
func FloatNonZero() Rule
FloatNonZero returns a floating-point validation rule for non zero.
func FloatNotBetween ¶
func FloatNotBetween[Min floating, Max floating](minimum Min, maximum Max) Rule
FloatNotBetween returns a floating-point validation rule for not between.
func FloatNotEqual ¶
func FloatNotEqual[T floating](expect T) Rule
FloatNotEqual returns a floating-point validation rule for not equal.
func FloatNotFinite ¶
func FloatNotFinite() Rule
FloatNotFinite returns a floating-point validation rule for not finite.
func FloatNotInfinite ¶
func FloatNotInfinite() Rule
FloatNotInfinite returns a floating-point validation rule for not infinite.
func FloatNotNaN ¶
func FloatNotNaN() Rule
FloatNotNaN returns a floating-point validation rule for not na n.
func FloatPositive ¶
func FloatPositive() Rule
FloatPositive returns a floating-point validation rule for positive.
func FloatPositiveInfinite ¶
func FloatPositiveInfinite() Rule
FloatPositiveInfinite returns a floating-point validation rule for positive infinite.
func IntBetween ¶
func IntBetween[Min integer, Max integer](minimum Min, maximum Max) Rule
IntBetween returns an integer validation rule for between.
func IntCompound ¶
func IntCompound() Rule
IntCompound returns an integer validation rule for compound.
func IntDivisibleBy ¶
func IntDivisibleBy[T integer](n T) Rule
IntDivisibleBy returns an integer validation rule for divisible by.
func IntEqual ¶
func IntEqual[T integer](expect T) Rule
IntEqual returns an integer validation rule for equal.
func IntGreaterThan ¶
func IntGreaterThan[T integer](expect T) Rule
IntGreaterThan returns an integer validation rule for greater than.
func IntGreaterThanOrEqual ¶
func IntGreaterThanOrEqual[T integer](expect T) Rule
IntGreaterThanOrEqual returns an integer validation rule for greater than or equal.
func IntHTTPStatus ¶
func IntHTTPStatus() Rule
IntHTTPStatus returns an integer validation rule for http status.
func IntLessThan ¶
func IntLessThan[T integer](expect T) Rule
IntLessThan returns an integer validation rule for less than.
func IntLessThanOrEqual ¶
func IntLessThanOrEqual[T integer](expect T) Rule
IntLessThanOrEqual returns an integer validation rule for less than or equal.
func IntMax ¶
func IntMax[T integer](expect T) Rule
IntMax returns an integer validation rule for max.
func IntMin ¶
func IntMin[T integer](expect T) Rule
IntMin returns an integer validation rule for min.
func IntMultipleOf ¶
func IntMultipleOf[T integer](n T) Rule
IntMultipleOf returns an integer validation rule for multiple of.
func IntNegative ¶
func IntNegative() Rule
IntNegative returns an integer validation rule for negative.
func IntNonNegative ¶
func IntNonNegative() Rule
IntNonNegative returns an integer validation rule for non negative.
func IntNonPositive ¶
func IntNonPositive() Rule
IntNonPositive returns an integer validation rule for non positive.
func IntNonZero ¶
func IntNonZero() Rule
IntNonZero returns an integer validation rule for non zero.
func IntNoneOf ¶
func IntNoneOf[T integer](restricted ...T) Rule
IntNoneOf returns an integer validation rule for none of.
func IntNotBetween ¶
func IntNotBetween[Min integer, Max integer](minimum Min, maximum Max) Rule
IntNotBetween returns an integer validation rule for not between.
func IntNotEqual ¶
func IntNotEqual[T integer](expect T) Rule
IntNotEqual returns an integer validation rule for not equal.
func IntOneOf ¶
func IntOneOf[T integer](allowed ...T) Rule
IntOneOf returns an integer validation rule for one of.
func IntPercentage ¶
func IntPercentage() Rule
IntPercentage returns an integer validation rule for percentage.
func IntPerfectSquare ¶
func IntPerfectSquare() Rule
IntPerfectSquare returns an integer validation rule for perfect square.
func IntPositive ¶
func IntPositive() Rule
IntPositive returns an integer validation rule for positive.
func IntPowerOfTwo ¶
func IntPowerOfTwo() Rule
IntPowerOfTwo returns an integer validation rule for power of two.
func MapAllowedKeys ¶
func MapAllowedKeys[K comparable](allowed ...K) Rule
MapAllowedKeys returns a map validation rule for allowed keys.
func MapContainsAllValues ¶
MapContainsAllValues returns a map validation rule for contains all values.
func MapContainsAnyValue ¶
MapContainsAnyValue returns a map validation rule for contains any value.
func MapContainsValue ¶
MapContainsValue returns a map validation rule for contains value.
func MapEqual ¶
func MapEqual[M ~map[K]V, K comparable, V any](expected M) Rule
MapEqual returns a map validation rule for equal.
func MapHasAllKeys ¶
func MapHasAllKeys[K comparable](expected ...K) Rule
MapHasAllKeys returns a map validation rule for has all keys.
func MapHasAnyKey ¶
func MapHasAnyKey[K comparable](expected ...K) Rule
MapHasAnyKey returns a map validation rule for has any key.
func MapHasExactKeys ¶
func MapHasExactKeys[K comparable](expected ...K) Rule
MapHasExactKeys returns a map validation rule for has exact keys.
func MapHasKey ¶
func MapHasKey[K comparable](expected K) Rule
MapHasKey returns a map validation rule for has key.
func MapHasNonZeroValue ¶
func MapHasNonZeroValue() Rule
MapHasNonZeroValue returns a map validation rule for has non zero value.
func MapHasNoneOfKeys ¶
func MapHasNoneOfKeys[K comparable](unexpected ...K) Rule
MapHasNoneOfKeys returns a map validation rule for has none of keys.
func MapLengthBetween ¶
MapLengthBetween returns a map validation rule for length between.
func MapLengthNotBetween ¶
MapLengthNotBetween returns a map validation rule for length not between.
func MapMaxLength ¶
MapMaxLength returns a map validation rule for max length.
func MapMinLength ¶
MapMinLength returns a map validation rule for min length.
func MapNoNilValues ¶
func MapNoNilValues() Rule
MapNoNilValues returns a map validation rule for no nil values.
func MapNoZeroValues ¶
func MapNoZeroValues() Rule
MapNoZeroValues returns a map validation rule for no zero values.
func MapNotContainsValue ¶
MapNotContainsValue returns a map validation rule for not contains value.
func MapNotEqual ¶
func MapNotEqual[M ~map[K]V, K comparable, V any](unexpected M) Rule
MapNotEqual returns a map validation rule for not equal.
func MapNotHasKey ¶
func MapNotHasKey[K comparable](unexpected K) Rule
MapNotHasKey returns a map validation rule for not has key.
func MapSubsetOf ¶
func MapSubsetOf[M ~map[K]V, K comparable, V any](expected M) Rule
MapSubsetOf returns a map validation rule for subset of.
func MapSupersetOf ¶
func MapSupersetOf[M ~map[K]V, K comparable, V any](expected M) Rule
MapSupersetOf returns a map validation rule for superset of.
func MapValueAt ¶
func MapValueAt[K comparable](key K, rules ...Rule) Rule
MapValueAt returns a map validation rule for value at.
func MapValueAtIfPresent ¶
func MapValueAtIfPresent[K comparable](key K, rules ...Rule) Rule
MapValueAtIfPresent returns a map validation rule for value at if present.
func NotNil ¶
func NotNil() Rule
NotNil rejects nil values. Values whose kinds cannot be nil always pass.
func Optional ¶
Optional skips rules for nil and empty values. Scalar values, including 0 and false, are not considered absent and are validated normally.
func Required ¶
func Required() Rule
Required rejects nil values and empty strings, arrays, slices, and maps. Scalar zero values such as 0 and false are considered present; combine it with NotZero when a non-zero scalar is required.
func StringAlphaNumeric ¶
func StringAlphaNumeric() Rule
StringAlphaNumeric returns a string validation rule for alpha numeric.
func StringContains ¶
StringContains returns a string validation rule for contains.
func StringContainsFold ¶
StringContainsFold returns a string validation rule for contains fold.
func StringEndsWith ¶
StringEndsWith returns a string validation rule for ends with.
func StringEndsWithFold ¶
StringEndsWithFold returns a string validation rule for ends with fold.
func StringLength ¶
StringLength returns a string validation rule for length.
func StringLowercase ¶
func StringLowercase() Rule
StringLowercase returns a string validation rule for lowercase.
func StringMaxLength ¶
StringMaxLength returns a string validation rule for max length.
func StringMinLength ¶
StringMinLength returns a string validation rule for min length.
func StringNotContains ¶
StringNotContains returns a string validation rule for not contains.
func StringNotContainsFold ¶
StringNotContainsFold returns a string validation rule for not contains fold.
func StringNotOneOf ¶
StringNotOneOf returns a string validation rule for not one of.
func StringNumeric ¶
func StringNumeric() Rule
StringNumeric returns a string validation rule for numeric.
func StringOneOf ¶
StringOneOf returns a string validation rule for one of.
func StringRegex ¶
StringRegex returns a string validation rule for regex.
func StringRequired ¶
func StringRequired() Rule
StringRequired returns a string validation rule for required.
func StringStartsWith ¶
StringStartsWith returns a string validation rule for starts with.
func StringStartsWithFold ¶
StringStartsWithFold returns a string validation rule for starts with fold.
func StringTrimmed ¶
func StringTrimmed() Rule
StringTrimmed returns a string validation rule for trimmed.
func StringUppercase ¶
func StringUppercase() Rule
StringUppercase returns a string validation rule for uppercase.
func UnlessContext ¶
UnlessContext applies rules when condition rejects the current RuleContext.
func WhenContext ¶
WhenContext applies rules when condition accepts the current RuleContext.
type RuleContext ¶
RuleContext contains the values available to a validation rule.
Root is the validated struct, Value is the selected field, and Path is the field path passed to Field.
func (RuleContext) RootAny ¶
func (context RuleContext) RootAny() any
RootAny returns the validated struct as an interface value. It returns nil when the root is invalid or cannot be interfaced.
func (RuleContext) ValueAny ¶
func (context RuleContext) ValueAny() any
ValueAny returns the selected field as an interface value. It returns nil when the value is invalid or cannot be interfaced.
Source Files
¶
- boolean.go
- bytes.go
- bytes_comparison.go
- bytes_content.go
- bytes_format.go
- bytes_internal.go
- bytes_length.go
- bytes_rules.go
- collection.go
- collection_comparison.go
- collection_content.go
- collection_internal.go
- collection_length.go
- collection_rules.go
- conditional.go
- core.go
- doc.go
- float.go
- float_comparison.go
- float_internal.go
- float_special.go
- integer.go
- integer_arithmetic.go
- integer_comparison.go
- integer_domain.go
- integer_internal.go
- map_comparison.go
- map_internal.go
- map_keys.go
- map_length.go
- map_values.go
- maps.go
- options.go
- string.go
- string_content.go
- string_format.go
- string_internal.go
- string_length.go
- universal.go
- utils.go