Documentation
¶
Index ¶
- func After(t time.Time) datacop.ValidationFunc
- func AllIn[T comparable](allowed ...T) datacop.ValidationFunc
- func Before(t time.Time) datacop.ValidationFunc
- func Between[T constraints.Ordered](min, max T) datacop.ValidationFunc
- func BetweenTime(start, end time.Time) datacop.ValidationFunc
- func Email(value any) bool
- func Equal[T comparable](other T) datacop.ValidationFunc
- func EqualLength(length int) datacop.ValidationFunc
- func EqualStrings(value, other string) bool
- func GreaterOrEqual[T cmp.Ordered](n T) datacop.ValidationFunc
- func GreaterThan[T cmp.Ordered](n T) datacop.ValidationFunc
- func In[T comparable](allowed ...T) datacop.ValidationFunc
- func LessOrEqual[T cmp.Ordered](n T) datacop.ValidationFunc
- func LessThan[T cmp.Ordered](n T) datacop.ValidationFunc
- func Match(pattern string) datacop.ValidationFunc
- func Max[T cmp.Ordered](max T) datacop.ValidationFunc
- func MaxLength(max int) datacop.ValidationFunc
- func Min[T cmp.Ordered](min T) datacop.ValidationFunc
- func MinLength(min int) datacop.ValidationFunc
- func NoDuplicates[T comparable]() datacop.ValidationFunc
- func NotZero[T comparable](value T) bool
- func Password(value any) bool
- func Phone(value any) bool
- func Required(value any) bool
- func Username(value any) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllIn ¶
func AllIn[T comparable](allowed ...T) datacop.ValidationFunc
AllIn checks if all values in a slice are in a set of allowed values
Example usage: AllIn(1, 2, 3)([]int{1, 2}) // returns true AllIn(1, 2, 3)([]int{1, 4}) // returns false AllIn("a", "b", "c")([]string{"a", "b"}) // returns true AllIn("a", "b", "c")([]string{"a", "d"}) // returns false
func Before ¶
func Before(t time.Time) datacop.ValidationFunc
Before checks if a time is before another
func Between ¶
func Between[T constraints.Ordered](min, max T) datacop.ValidationFunc
Between checks if a value is between a minimum and maximum value Example usage:
Between(10, 20)(15) // returns true Between(10, 20)(25) // returns false
func BetweenTime ¶
func BetweenTime(start, end time.Time) datacop.ValidationFunc
BetweenTime checks if a value is between two other values
Example usage: BetweenTime(time.Now().Add(-1*time.Hour), time.Now().Add(1*time.Hour))(time.Now()) // returns true BetweenTime(time.Now().Add(-1*time.Hour), time.Now().Add(-30*time.Minute))(time.Now()) // returns false
func Email ¶
Email is a very simple email validation function. For a more comprehensive email validation, consider using a package like github.com/patrickward/mailcop.
Example usage: Email("[email protected]") // returns true Email("invalid-email") // returns false
func Equal ¶
func Equal[T comparable](other T) datacop.ValidationFunc
Equal checks if values are equal Example usage: Equal(10)(10) // returns true Equal(10)(5) // returns false
func EqualLength ¶ added in v0.0.3
func EqualLength(length int) datacop.ValidationFunc
EqualLength returns a validation function that checks if a string has a specific length
Example usage: EqualLength(5)("hello") // returns true EqualLength(5)("hi") // returns false EqualLength(5)("hello!") // returns false
func EqualStrings ¶
EqualStrings checks if two strings are equal
Example usage: EqualStrings("test", "test") // returns true EqualStrings("test", "TEST") // returns false
func GreaterOrEqual ¶
func GreaterOrEqual[T cmp.Ordered](n T) datacop.ValidationFunc
GreaterOrEqual returns a validation function that checks if a value is greater than or equal to a specified value
Example usage: GreaterOrEqual(10)(15) // returns true GreaterOrEqual(10)(10) // returns true GreaterOrEqual(10)(5) // returns false
func GreaterThan ¶
func GreaterThan[T cmp.Ordered](n T) datacop.ValidationFunc
GreaterThan returns a validation function that checks if a value is greater than a specified value
Example usage:
GreaterThan(10)(15) // returns true GreaterThan(10)(5) // returns false
func In ¶
func In[T comparable](allowed ...T) datacop.ValidationFunc
In checks if a value is in a set of allowed values
Example usage: In(1, 2, 3)(2) // returns true In(1, 2, 3)(4) // returns false In("a", "b", "c")("b") // returns true In("a", "b", "c")("d") // returns false
func LessOrEqual ¶
func LessOrEqual[T cmp.Ordered](n T) datacop.ValidationFunc
LessOrEqual returns a validation function that checks if a value is less than or equal to a specified value
Example usage: LessOrEqual(10)(5) // returns true LessOrEqual(10)(10) // returns true LessOrEqual(10)(15) // returns false
func LessThan ¶
func LessThan[T cmp.Ordered](n T) datacop.ValidationFunc
LessThan returns a validation function that checks if a value is less than a specified value
Example usage: LessThan(10)(5) // returns true LessThan(10)(15) // returns false
func Match ¶
func Match(pattern string) datacop.ValidationFunc
Match returns a validation function that checks if a string matches a pattern
Example usage: Match(`^[a-zA-Z0-9]+$`)(username) // returns true if username is alphanumeric Match(`^[a-zA-Z0-9]+$`)(email) // returns false if email is not alphanumeric
func Max ¶
func Max[T cmp.Ordered](max T) datacop.ValidationFunc
Max returns a validation function that checks maximum value
Example usage: Max(10)(5) // returns true Max(10)(15) // returns false
func MaxLength ¶
func MaxLength(max int) datacop.ValidationFunc
MaxLength returns a validation function that checks maximum string length
Example usage: MaxLength(5)("hello") // returns false MaxLength(5)("hi") // returns true
func Min ¶
func Min[T cmp.Ordered](min T) datacop.ValidationFunc
Min returns a validation function that checks minimum value
Example usage: Min(10)(15) // returns true Min(10)(5) // returns false
func MinLength ¶
func MinLength(min int) datacop.ValidationFunc
MinLength returns a validation function that checks minimum string length
Example usage: MinLength(5)("hello") // returns true MinLength(5)("hi") // returns false
func NoDuplicates ¶
func NoDuplicates[T comparable]() datacop.ValidationFunc
NoDuplicates checks if a slice contains any duplicate values
Example usage: NoDuplicates()([]int{1, 2, 3}) // returns true NoDuplicates()([]int{1, 2, 2}) // returns false
func NotZero ¶
func NotZero[T comparable](value T) bool
NotZero checks if a numeric value is not a zero value
func Password ¶
Password returns common password validation rules. This is an example of a function that could be used in a project's own validation library, combining common validation rules into a single function.
func Phone ¶
Phone is a simple phone number validation function. It expects a string with a format of 123-456-7890.
Types ¶
This section is empty.