Documentation ¶
Index ¶
- Variables
- type Errors
- type Numeric
- type RuleSet
- func EQ[T comparable](v T) RuleSet
- func GT[T Numeric](n T) RuleSet
- func GTE[T Numeric](n T) RuleSet
- func In[T any](values []T) RuleSet
- func LT[T Numeric](n T) RuleSet
- func LTE[T Numeric](n T) RuleSet
- func Max(n int) RuleSet
- func Min(n int) RuleSet
- func Rules(rules ...RuleSet) []RuleSet
- func TimeAfter(t time.Time) RuleSet
- func TimeBefore(t time.Time) RuleSet
- type Schema
Constants ¶
This section is empty.
Variables ¶
View Source
var ContainsDigit = RuleSet{ Name: "containsDigit", ValidateFunc: func(rule RuleSet) bool { str, ok := rule.FieldValue.(string) if !ok { return false } return hasDigit(str) }, MessageFunc: func(set RuleSet) string { return "must contain at least 1 numeric character" }, }
View Source
var ContainsSpecial = RuleSet{ Name: "containsSpecial", ValidateFunc: func(rule RuleSet) bool { str, ok := rule.FieldValue.(string) if !ok { return false } return hasSpecialChar(str) }, MessageFunc: func(set RuleSet) string { return "must contain at least 1 special character" }, }
View Source
var ContainsUpper = RuleSet{ Name: "containsUpper", ValidateFunc: func(rule RuleSet) bool { str, ok := rule.FieldValue.(string) if !ok { return false } for _, ch := range str { if unicode.IsUpper(rune(ch)) { return true } } return false }, MessageFunc: func(set RuleSet) string { return "must contain at least 1 uppercase character" }, }
View Source
var Email = RuleSet{ Name: "email", MessageFunc: func(set RuleSet) string { return "is not a valid email address" }, ValidateFunc: func(set RuleSet) bool { email, ok := set.FieldValue.(string) if !ok { return false } return emailRegex.MatchString(email) }, }
View Source
var Required = RuleSet{ Name: "required", MessageFunc: func(set RuleSet) string { return "is a required field" }, ValidateFunc: func(rule RuleSet) bool { str, ok := rule.FieldValue.(string) if !ok { return false } return len(str) > 0 }, }
View Source
var Time = RuleSet{ Name: "time", ValidateFunc: func(set RuleSet) bool { t, ok := set.FieldValue.(time.Time) if !ok { return false } return t.After(time.Time{}) }, MessageFunc: func(set RuleSet) string { return "is not a valid time" }, }
Functions ¶
This section is empty.
Types ¶
type Errors ¶
Errors is a map holding all the possible errors that may occur during validation.
type RuleSet ¶
type RuleSet struct { Name string RuleValue any FieldValue any FieldName any ErrorMessage string MessageFunc func(RuleSet) string ValidateFunc func(RuleSet) bool }
RuleSet holds the state of a single rule.
func EQ ¶
func EQ[T comparable](v T) RuleSet
func TimeBefore ¶
Click to show internal directories.
Click to hide internal directories.