Documentation
¶
Index ¶
- func After(t time.Time) types.Rule[time.Time]
- func And[T any](rules ...types.Rule[T]) types.Rule[T]
- func Before(t time.Time) types.Rule[time.Time]
- func Between(min, max time.Time) types.Rule[time.Time]
- func ContainsAnyChar[T ~string](chars string) types.Rule[T]
- func ContainsElem[S ~[]T, T comparable](s *S, v T) types.Rule[S]
- func ContainsRune[T ~string](r rune) types.Rule[T]
- func ContainsString[T ~string](substr string) types.Rule[T]
- func Deref[T any](rules ...types.Rule[*T]) types.Rule[T]
- func Equal[T comparable](eq T) types.Rule[T]
- func EqualIgnoreCase[T ~string](eq string) types.Rule[T]
- func EqualMap[M ~map[K]T, K, T comparable](m M) types.Rule[M]
- func EqualMapFunc[M1 ~map[K]T1, M2 ~map[K]T2, K comparable, T1, T2 any](m *M1, m2 M2, eq func(T1, T2) bool) types.Rule[M1]
- func EqualSlice[S ~[]T, T comparable](s2 S) types.Rule[S]
- func EqualSliceFunc[S1 ~[]T1, S2 ~[]T2, T1, T2 any](s *S1, s2 S2, eq func(T1, T2) bool) types.Rule[S1]
- func EqualToAny[T comparable](eq ...T) types.Rule[T]
- func ForEach[S ~[]T, T any](s *S, rule types.Rule[T]) types.Rule[S]
- func ForEachKey[M ~map[K]T, K comparable, T any](m *M, rule types.Rule[K]) types.Rule[M]
- func ForEachValue[M ~map[K]T, K comparable, T any](m *M, rule types.Rule[T]) types.Rule[M]
- func ForKey[M ~map[K]T, K comparable, T any](m *M, key K, rule types.Rule[T]) types.Rule[M]
- func GreaterThan[T cmp.Ordered](ge T) types.Rule[T]
- func GreaterThanEqual[T cmp.Ordered](ge T) types.Rule[T]
- func HasPrefix[T ~string](prefix string) types.Rule[T]
- func HasSuffix[T ~string](suffix string) types.Rule[T]
- func If[T any](condition bool, conditionalRule types.Rule[T]) types.Rule[T]
- func InTheFuture() types.Rule[time.Time]
- func InTheFutureOrPresent() types.Rule[time.Time]
- func InThePast() types.Rule[time.Time]
- func InThePastOrPresent() types.Rule[time.Time]
- func IsBlank[T ~string]() types.Rule[T]
- func IsFalse[T ~bool]() types.Rule[T]
- func IsNil[T any]() types.Rule[*T]
- func IsNotNil[T any]() types.Rule[*T]
- func IsNotZeroValue[T comparable]() types.Rule[T]
- func IsSorted[S ~[]T, T cmp.Ordered](s *S) types.Rule[S]
- func IsSortedFunc[S ~[]T, T any](s *S, cmpFn func(T, T) int) types.Rule[S]
- func IsTrue[T ~bool]() types.Rule[T]
- func IsValid[T validation.Validatable]() types.Rule[T]
- func IsZeroValue[T comparable]() types.Rule[T]
- func LengthMap[M ~map[K]T, K comparable, T any](m *M, l int) types.Rule[M]
- func LengthRune[T ~string](l int) types.Rule[T]
- func LengthSlice[S ~[]T, T any](s *S, l int) types.Rule[S]
- func LengthString[T ~string](l int) types.Rule[T]
- func LessThan[T cmp.Ordered](le T) types.Rule[T]
- func LessThanEqual[T cmp.Ordered](le T) types.Rule[T]
- func MatchBytes[T ~[]byte](re *regexp.Regexp) types.Rule[T]
- func MatchString[T ~string](re *regexp.Regexp) types.Rule[T]
- func Max[T cmp.Ordered](max T) types.Rule[T]
- func MaxLengthMap[M ~map[K]T, K comparable, T any](m *M, l int) types.Rule[M]
- func MaxLengthRune[T ~string](l int) types.Rule[T]
- func MaxLengthSlice[S ~[]T, T any](s *S, l int) types.Rule[S]
- func MaxLengthString[T ~string](l int) types.Rule[T]
- func Min[T cmp.Ordered](min T) types.Rule[T]
- func MinLengthMap[M ~map[K]T, K comparable, T any](m *M, l int) types.Rule[M]
- func MinLengthRune[T ~string](l int) types.Rule[T]
- func MinLengthSlice[S ~[]T, T any](s *S, l int) types.Rule[S]
- func MinLengthString[T ~string](l int) types.Rule[T]
- func Negative[T cmp.Ordered]() types.Rule[T]
- func NegativeOrZero[T cmp.Ordered]() types.Rule[T]
- func NotBlank[T ~string]() types.Rule[T]
- func NotContainsAnyChar[T ~string](chars string) types.Rule[T]
- func NotContainsElem[S ~[]T, T comparable](s *S, v T) types.Rule[S]
- func NotContainsRune[T ~string](r rune) types.Rule[T]
- func NotContainsString[T ~string](substr string) types.Rule[T]
- func NotEqual[T comparable](ne T) types.Rule[T]
- func NotEqualIgnoreCase[T ~string](eq string) types.Rule[T]
- func NotEqualToAny[T comparable](ne ...T) types.Rule[T]
- func NotHasPrefix[T ~string](prefix string) types.Rule[T]
- func NotHasSuffix[T ~string](suffix string) types.Rule[T]
- func NotInRange[T cmp.Ordered](min, max T) types.Rule[T]
- func NotMatchBytes[T ~[]byte](re *regexp.Regexp) types.Rule[T]
- func NotMatchString[T ~string](re *regexp.Regexp) types.Rule[T]
- func OnDate(t time.Time) types.Rule[time.Time]
- func Or[T any](rules ...types.Rule[T]) types.Rule[T]
- func Positive[T cmp.Ordered]() types.Rule[T]
- func PositiveOrZero[T cmp.Ordered]() types.Rule[T]
- func Range[T cmp.Ordered](min, max T) types.Rule[T]
- func Ref[T any](rules ...types.Rule[T]) types.Rule[*T]
- func Unique[S ~[]T, T comparable](s *S) types.Rule[S]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsAnyChar ¶
ContainsAnyChar validates that the string contains any Unicode code point in chars.
func ContainsElem ¶
func ContainsElem[S ~[]T, T comparable](s *S, v T) types.Rule[S]
ContainsElem validates that the slice contains v.
func ContainsRune ¶
ContainsRune validates that the string contains the given rune.
func ContainsString ¶
ContainsString validates that the string contains substr.
func EqualIgnoreCase ¶
EqualIgnoreCase validates that the string equals eq, ignoring case.
func EqualMap ¶
func EqualMap[M ~map[K]T, K, T comparable](m M) types.Rule[M]
EqualMap validates that the map is equal to m using comparable value equality.
func EqualMapFunc ¶
func EqualMapFunc[M1 ~map[K]T1, M2 ~map[K]T2, K comparable, T1, T2 any](m *M1, m2 M2, eq func(T1, T2) bool) types.Rule[M1]
EqualMapFunc validates that the map is equal to m2 using a custom equality function. m is only passed to help the compiler with type inference.
func EqualSlice ¶
func EqualSlice[S ~[]T, T comparable](s2 S) types.Rule[S]
EqualSlice validates that the slice is equal to s2.
func EqualSliceFunc ¶
func EqualSliceFunc[S1 ~[]T1, S2 ~[]T2, T1, T2 any](s *S1, s2 S2, eq func(T1, T2) bool) types.Rule[S1]
EqualSliceFunc validates that the slice is equal to s2 using a custom equality function. s is only passed to help the compiler with type inference.
func EqualToAny ¶
func EqualToAny[T comparable](eq ...T) types.Rule[T]
EqualToAny validates that the value equals at least one of the provided values.
func ForEachKey ¶
ForEachKey validates each map key against the provided rule.
func ForEachValue ¶
ForEachValue validates each map value against the provided rule.
func ForKey ¶
ForKey validates the value at a specific map key against the provided rule. Returns an error if the key is not present in the map.
func GreaterThan ¶
GreaterThan validates that the value is strictly greater than ge.
func GreaterThanEqual ¶
GreaterThanEqual validates that the value is greater than or equal to ge.
func If ¶
If returns the rule when condition is true, or nil when false. The nil result is safely skipped by And and the validation layer — do not call it directly.
func InTheFuture ¶
InTheFuture validates that the time is after the current time.
func InTheFutureOrPresent ¶
InTheFutureOrPresent validates that the time is after or equal to the current time.
func InThePastOrPresent ¶
InThePastOrPresent validates that the time is before or equal to the current time.
func IsNotZeroValue ¶
func IsNotZeroValue[T comparable]() types.Rule[T]
IsNotZeroValue validates that the value does not equal its type's zero value.
func IsSorted ¶
IsSorted validates that the slice is sorted in ascending order. s is only passed to help the compiler with type inference.
func IsSortedFunc ¶
IsSortedFunc validates that the slice is sorted according to the provided comparison function. s is only passed to help the compiler with type inference.
func IsValid ¶
func IsValid[T validation.Validatable]() types.Rule[T]
IsValid validates that the value passes its own Validation() rules.
func IsZeroValue ¶
func IsZeroValue[T comparable]() types.Rule[T]
IsZeroValue validates that the value equals its type's zero value.
func LengthMap ¶
func LengthMap[M ~map[K]T, K comparable, T any](m *M, l int) types.Rule[M]
LengthMap validates that the map has exactly l entries.
func LengthRune ¶
LengthRune validates that the string contains exactly l Unicode code points (runes). Note: a single visible character may span multiple code points. For example, the family emoji 👨👩👧 is composed of several code points joined by zero-width joiners, so LengthRune counts it as more than 1. If you need to validate display length (e.g. for usernames shown in a UI), use a grapheme-cluster-aware library such as github.com/rivo/uniseg instead.
func LengthSlice ¶
LengthSlice validates that the slice has exactly l elements.
func LengthString ¶
LengthString validates that the string has exactly l bytes. Use LengthRune for character count.
func LessThanEqual ¶
LessThanEqual validates that the value is less than or equal to le.
func MatchBytes ¶
MatchBytes validates that the byte slice matches the provided regular expression.
func MatchString ¶
MatchString validates that the string matches the provided regular expression.
func MaxLengthMap ¶
func MaxLengthMap[M ~map[K]T, K comparable, T any](m *M, l int) types.Rule[M]
MaxLengthMap validates that the map has at most l entries.
func MaxLengthRune ¶
MaxLengthRune validates that the string contains at most l Unicode code points.
func MaxLengthSlice ¶
MaxLengthSlice validates that the slice has at most l elements.
func MaxLengthString ¶
MaxLengthString validates that the string has at most l bytes.
func MinLengthMap ¶
func MinLengthMap[M ~map[K]T, K comparable, T any](m *M, l int) types.Rule[M]
MinLengthMap validates that the map has at least l entries.
func MinLengthRune ¶
MinLengthRune validates that the string contains at least l Unicode code points.
func MinLengthSlice ¶
MinLengthSlice validates that the slice has at least l elements.
func MinLengthString ¶
MinLengthString validates that the string has at least l bytes.
func NegativeOrZero ¶
NegativeOrZero validates that the value is less than or equal to zero.
func NotContainsAnyChar ¶
NotContainsAnyChar validates that the string contains none of the Unicode code points in chars.
func NotContainsElem ¶
func NotContainsElem[S ~[]T, T comparable](s *S, v T) types.Rule[S]
NotContainsElem validates that the slice does not contain v.
func NotContainsRune ¶
NotContainsRune validates that the string does not contain the given rune.
func NotContainsString ¶
NotContainsString validates that the string does not contain substr.
func NotEqual ¶
func NotEqual[T comparable](ne T) types.Rule[T]
NotEqual validates that the value does not equal ne.
func NotEqualIgnoreCase ¶
NotEqualIgnoreCase validates that the string does not equal eq, ignoring case.
func NotEqualToAny ¶
func NotEqualToAny[T comparable](ne ...T) types.Rule[T]
NotEqualToAny validates that the value does not equal any of the provided values.
func NotHasPrefix ¶
NotHasPrefix validates that the string does not have the given prefix.
func NotHasSuffix ¶
NotHasSuffix validates that the string does not have the given suffix.
func NotInRange ¶
NotInRange validates that the value is not between min and max inclusive.
func NotMatchBytes ¶
NotMatchBytes validates that the byte slice does not match the provided regular expression.
func NotMatchString ¶
NotMatchString validates that the string does not match the provided regular expression.
func OnDate ¶
OnDate validates that the time falls on the same calendar date as t, using t's location.
func Or ¶
Or combines multiple rules into one, returning nil if any rule passes. Returns the last error if all rules fail. Nil rules are skipped.
func PositiveOrZero ¶
PositiveOrZero validates that the value is greater than or equal to zero.
func Unique ¶
func Unique[S ~[]T, T comparable](s *S) types.Rule[S]
Unique validates that all elements in the slice are distinct.
Types ¶
This section is empty.