vee

package module
v0.0.0-...-2ac8fa8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 8 Imported by: 0

README

vee: Simple Go Validation

Check unit tests to see how to use vee

Documentation

Index

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

func FieldError(name string, err error) error

Types

type CheckSemantic

type CheckSemantic int
const (
	CheckSemanticFirst CheckSemantic = iota
	CheckSemanticAll
)

type Checkable

type Checkable interface {
	Check() error
}

func Func

func Func(f func() error) Checkable

func Schema

func Schema(cons ...Checkable) Checkable

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 Regex

func Regex(regex *regexp.Regexp) CheckableValue[string]

func Required

func Required[T any]() CheckableValue[T]

func StrLen

func StrLen(min int, max int) CheckableValue[string]

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

type ContainsConstraint struct {
	Value string
	Str   string
	Any   bool
}

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 (*ContainsPredicateConstraint) SetValue

func (c *ContainsPredicateConstraint) SetValue(value string)

type EachConstraint

type EachConstraint[T ~[]E, E any] struct {
	Value      T
	Constraint CheckableValue[E]
}

func (*EachConstraint[T, E]) Check

func (c *EachConstraint[T, E]) Check() error

func (*EachConstraint[T, E]) SetValue

func (c *EachConstraint[T, E]) SetValue(value T)

type ErrField

type ErrField struct {
	FieldName string
	Err       error
}

func (ErrField) Error

func (ef ErrField) Error() string

type ErrList

type ErrList []error

func (ErrList) Dto

func (el ErrList) Dto() []map[string]string

func (ErrList) Error

func (el ErrList) Error() string

type FieldConstraint

type FieldConstraint[T any] struct {
	Constraint CheckableValue[T]
	FieldName  string
}

func (*FieldConstraint[T]) Check

func (c *FieldConstraint[T]) Check() error

func (*FieldConstraint[T]) SetValue

func (c *FieldConstraint[T]) SetValue(value T)

type FuncConstraint

type FuncConstraint struct {
	Func func() error
}

func (*FuncConstraint) Check

func (c *FuncConstraint) Check() error

type IfConstraint

type IfConstraint[T any] struct {
	Value      T
	Predicate  func() bool
	Constraint CheckableValue[T]
}

func (*IfConstraint[T]) Check

func (c *IfConstraint[T]) Check() error

func (*IfConstraint[T]) SetValue

func (c *IfConstraint[T]) SetValue(value 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]
}

func (*IfNotNilConstraint[T, E]) Check

func (c *IfNotNilConstraint[T, E]) Check() error

func (*IfNotNilConstraint[T, E]) SetValue

func (c *IfNotNilConstraint[T, E]) SetValue(value T)

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

type LenConstraint[T any] struct {
	Value T
	Min   int
	Max   int
}

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
}

func (*MaxConstraint[T]) Check

func (c *MaxConstraint[T]) Check() error

func (*MaxConstraint[T]) SetValue

func (c *MaxConstraint[T]) SetValue(value T)

type MinConstraint

type MinConstraint[T constraints.Ordered] struct {
	Value T
	Min   T
}

func (*MinConstraint[T]) Check

func (c *MinConstraint[T]) Check() error

func (*MinConstraint[T]) SetValue

func (c *MinConstraint[T]) SetValue(value 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
}

func (*NotInConstraint[T]) Check

func (c *NotInConstraint[T]) Check() error

func (*NotInConstraint[T]) SetValue

func (c *NotInConstraint[T]) SetValue(value T)

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

type RegexConstraint struct {
	Value string
	Error string
	Regex *regexp.Regexp
}

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
}

func (*SchemaConstraint) Check

func (c *SchemaConstraint) Check() error

type StrLenConstraint

type StrLenConstraint struct {
	Value     string
	MinLength int
	MaxLength int
}

func (*StrLenConstraint) Check

func (c *StrLenConstraint) Check() error

func (*StrLenConstraint) SetValue

func (c *StrLenConstraint) SetValue(value string)

type StrMaxLenConstraint

type StrMaxLenConstraint struct {
	Value     string
	MaxLength int
}

func (*StrMaxLenConstraint) Check

func (c *StrMaxLenConstraint) Check() error

func (*StrMaxLenConstraint) SetValue

func (c *StrMaxLenConstraint) SetValue(value string)

type StrMinLenConstraint

type StrMinLenConstraint struct {
	Value     string
	MinLength int
}

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]
}

func (*ValueConstraint[T]) Check

func (c *ValueConstraint[T]) Check() error

func (*ValueConstraint[T]) SetValue

func (c *ValueConstraint[T]) SetValue(value T)

type ValueConstraints

type ValueConstraints[T any] struct {
	Value       T
	Constraints []CheckableValue[T]
	Semantic    CheckSemantic
}

func (*ValueConstraints[T]) Check

func (c *ValueConstraints[T]) Check() error

func (*ValueConstraints[T]) SetValue

func (c *ValueConstraints[T]) SetValue(value T)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL