Documentation ¶
Index ¶
- Variables
- func FieldError(name string, err error) error
- type CheckSemantic
- type Checkable
- type CheckableValue
- func All[T any](cons ...CheckableValue[T]) CheckableValue[T]
- func Constraints[T any](semantic CheckSemantic, cons ...CheckableValue[T]) CheckableValue[T]
- func Contains(str string) CheckableValue[string]
- func ContainsAny(str string) CheckableValue[string]
- func ContainsLower() CheckableValue[string]
- func ContainsNumber() CheckableValue[string]
- func ContainsPredicate(predicate func(rune) bool, message string) CheckableValue[string]
- func ContainsUpper() CheckableValue[string]
- func Each[T ~[]E, E any](cons ...CheckableValue[E]) CheckableValue[T]
- func Email() CheckableValue[string]
- func Field[T any](name string, value T, cons ...CheckableValue[T]) CheckableValue[T]
- func First[T any](cons ...CheckableValue[T]) CheckableValue[T]
- func If[T any](predicate func() bool, cons ...CheckableValue[T]) CheckableValue[T]
- func IfNotBlank(cons ...CheckableValue[string]) CheckableValue[string]
- func IfNotNil[T ~*E, E any](cons ...CheckableValue[E]) CheckableValue[T]
- func In[T comparable](values map[T]bool) CheckableValue[T]
- func Len[T any](min, max int) CheckableValue[T]
- func Max[T constraints.Ordered](max T) CheckableValue[T]
- func Min[T constraints.Ordered](min T) CheckableValue[T]
- func NotBlank() CheckableValue[string]
- func NotIn[T comparable](values map[T]bool) CheckableValue[T]
- func Range[T constraints.Ordered](min, max T) CheckableValue[T]
- func Regex(regex *regexp.Regexp) CheckableValue[string]
- func Required[T any]() CheckableValue[T]
- func StrLen(min int, max int) CheckableValue[string]
- func StrMaxLen(max int) CheckableValue[string]
- func StrMinLen(min int) CheckableValue[string]
- func Value[T any](value T, cons ...CheckableValue[T]) CheckableValue[T]
- type ContainsConstraint
- type ContainsPredicateConstraint
- type EachConstraint
- type ErrField
- type ErrList
- type FieldConstraint
- type FuncConstraint
- type IfConstraint
- type IfNotBlankConstraint
- type IfNotNilConstraint
- type InConstraint
- type LenConstraint
- type MaxConstraint
- type MinConstraint
- type NotBlankConstraint
- type NotInConstraint
- type RangeConstraint
- type RegexConstraint
- type RequiredConstraint
- type SchemaConstraint
- type StrLenConstraint
- type StrMaxLenConstraint
- type StrMinLenConstraint
- type Validatable
- type ValueConstraint
- type ValueConstraints
Constants ¶
This section is empty.
Variables ¶
View Source
var (
DefaultCheckSemantic = CheckSemanticFirst
)
View Source
var EmailRegex = regexp.MustCompile(`^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$`)
Functions ¶
func FieldError ¶
Types ¶
type CheckSemantic ¶
type CheckSemantic int
const ( CheckSemanticFirst CheckSemantic = iota CheckSemanticAll )
type CheckableValue ¶
type CheckableValue[T any] interface { Checkable SetValue(value T) // TODO: consider returning CheckableValue[T] }
func All ¶
func All[T any](cons ...CheckableValue[T]) CheckableValue[T]
func Constraints ¶
func Constraints[T any](semantic CheckSemantic, cons ...CheckableValue[T]) CheckableValue[T]
func Contains ¶
func Contains(str string) CheckableValue[string]
func ContainsAny ¶
func ContainsAny(str string) CheckableValue[string]
func ContainsLower ¶
func ContainsLower() CheckableValue[string]
func ContainsNumber ¶
func ContainsNumber() CheckableValue[string]
func ContainsPredicate ¶
func ContainsPredicate(predicate func(rune) bool, message string) CheckableValue[string]
func ContainsUpper ¶
func ContainsUpper() CheckableValue[string]
func Each ¶
func Each[T ~[]E, E any](cons ...CheckableValue[E]) CheckableValue[T]
func Email ¶
func Email() CheckableValue[string]
func Field ¶
func Field[T any](name string, value T, cons ...CheckableValue[T]) CheckableValue[T]
func First ¶
func First[T any](cons ...CheckableValue[T]) CheckableValue[T]
func If ¶
func If[T any](predicate func() bool, cons ...CheckableValue[T]) CheckableValue[T]
func IfNotBlank ¶
func IfNotBlank(cons ...CheckableValue[string]) CheckableValue[string]
func IfNotNil ¶
func IfNotNil[T ~*E, E any](cons ...CheckableValue[E]) CheckableValue[T]
func In ¶
func In[T comparable](values map[T]bool) CheckableValue[T]
func Len ¶
func Len[T any](min, max int) CheckableValue[T]
func Max ¶
func Max[T constraints.Ordered](max T) CheckableValue[T]
func Min ¶
func Min[T constraints.Ordered](min T) CheckableValue[T]
func NotBlank ¶
func NotBlank() CheckableValue[string]
func NotIn ¶
func NotIn[T comparable](values map[T]bool) CheckableValue[T]
func Range ¶
func Range[T constraints.Ordered](min, max T) CheckableValue[T]
func Required ¶
func Required[T any]() CheckableValue[T]
func StrMaxLen ¶
func StrMaxLen(max int) CheckableValue[string]
func StrMinLen ¶
func StrMinLen(min int) CheckableValue[string]
func Value ¶
func Value[T any](value T, cons ...CheckableValue[T]) CheckableValue[T]
type ContainsConstraint ¶
func (*ContainsConstraint) Check ¶
func (c *ContainsConstraint) Check() error
func (*ContainsConstraint) SetValue ¶
func (c *ContainsConstraint) SetValue(value string)
type ContainsPredicateConstraint ¶
type ContainsPredicateConstraint struct { Value string ErrorMessage string Predicate func(rune) bool }
func (*ContainsPredicateConstraint) Check ¶
func (c *ContainsPredicateConstraint) Check() error
func (*ContainsPredicateConstraint) SetValue ¶
func (c *ContainsPredicateConstraint) SetValue(value string)
type EachConstraint ¶
type EachConstraint[T ~[]E, E any] struct { Value T Constraint CheckableValue[E] }
type FieldConstraint ¶
type FieldConstraint[T any] struct { Constraint CheckableValue[T] FieldName string }
type FuncConstraint ¶
type FuncConstraint struct {
Func func() error
}
type IfConstraint ¶
type IfConstraint[T any] struct { Value T Predicate func() bool Constraint CheckableValue[T] }
type IfNotBlankConstraint ¶
type IfNotBlankConstraint struct { Value string Constraint CheckableValue[string] }
func (*IfNotBlankConstraint) Check ¶
func (c *IfNotBlankConstraint) Check() error
func (*IfNotBlankConstraint) SetValue ¶
func (c *IfNotBlankConstraint) SetValue(value string)
type IfNotNilConstraint ¶
type IfNotNilConstraint[T ~*E, E any] struct { Value T Constraint CheckableValue[E] }
type InConstraint ¶
type InConstraint[T comparable] struct { Value T ValidValues map[T]bool }
func (*InConstraint[T]) Check ¶
func (c *InConstraint[T]) Check() error
func (*InConstraint[T]) SetValue ¶
func (c *InConstraint[T]) SetValue(value T)
type LenConstraint ¶
func (*LenConstraint[T]) Check ¶
func (c *LenConstraint[T]) Check() error
func (*LenConstraint[T]) SetValue ¶
func (c *LenConstraint[T]) SetValue(value T)
type MaxConstraint ¶
type MaxConstraint[T constraints.Ordered] struct { Value T Max T }
type MinConstraint ¶
type MinConstraint[T constraints.Ordered] struct { Value T Min T }
type NotBlankConstraint ¶
type NotBlankConstraint struct {
Value string
}
func (*NotBlankConstraint) Check ¶
func (c *NotBlankConstraint) Check() error
func (*NotBlankConstraint) SetValue ¶
func (c *NotBlankConstraint) SetValue(value string)
type NotInConstraint ¶
type NotInConstraint[T comparable] struct { Value T InvalidValues map[T]bool }
type RangeConstraint ¶
type RangeConstraint[T constraints.Ordered] struct { Value T Min T Max T }
func (*RangeConstraint[T]) Check ¶
func (c *RangeConstraint[T]) Check() error
func (*RangeConstraint[T]) SetValue ¶
func (c *RangeConstraint[T]) SetValue(value T)
type RegexConstraint ¶
func (*RegexConstraint) Check ¶
func (c *RegexConstraint) Check() (err error)
func (*RegexConstraint) SetValue ¶
func (c *RegexConstraint) SetValue(value string)
type RequiredConstraint ¶
type RequiredConstraint[T any] struct { Value T }
func (*RequiredConstraint[T]) Check ¶
func (c *RequiredConstraint[T]) Check() error
func (*RequiredConstraint[T]) SetValue ¶
func (c *RequiredConstraint[T]) SetValue(value T)
type SchemaConstraint ¶
type SchemaConstraint struct {
Constraints []Checkable
}
type StrLenConstraint ¶
func (*StrLenConstraint) Check ¶
func (c *StrLenConstraint) Check() error
func (*StrLenConstraint) SetValue ¶
func (c *StrLenConstraint) SetValue(value string)
type StrMaxLenConstraint ¶
func (*StrMaxLenConstraint) Check ¶
func (c *StrMaxLenConstraint) Check() error
func (*StrMaxLenConstraint) SetValue ¶
func (c *StrMaxLenConstraint) SetValue(value string)
type StrMinLenConstraint ¶
func (*StrMinLenConstraint) Check ¶
func (c *StrMinLenConstraint) Check() error
func (*StrMinLenConstraint) SetValue ¶
func (c *StrMinLenConstraint) SetValue(value string)
type Validatable ¶
type Validatable interface {
Validate() error
}
type ValueConstraint ¶
type ValueConstraint[T any] struct { Value T Constraint CheckableValue[T] }
type ValueConstraints ¶
type ValueConstraints[T any] struct { Value T Constraints []CheckableValue[T] Semantic CheckSemantic }
Click to show internal directories.
Click to hide internal directories.