Documentation ¶
Index ¶
- Variables
- func CanMarshalJSON(t reflect.Type) bool
- func DeepValidate(v any) error
- func ReduceSet[S ~map[T]struct{}, T cmp.Ordered, R any](set S, reduceFunc func(last R, val T) R) (result R)
- func ReduceSlice[S ~[]T, T cmp.Ordered, R any](slice S, reduceFunc func(last R, val T) R) (result R)
- func ReflectCompare(a, b reflect.Value) int
- func SetToRandomizedSlice[S ~map[T]struct{}, T cmp.Ordered](set S) []T
- func SetToSortedSlice[S ~map[T]struct{}, T cmp.Ordered](set S) []T
- func SliceContainsAll[T comparable](outer []T, inner ...T) bool
- func SliceContainsAny[T comparable](outer []T, inner ...T) bool
- func TryValidate(v any) (err error, isValidatable bool)
- func Validate(v any) error
- type Finder
- type KeyMutex
- type LenString
- func (s *LenString) MarshalJSON() (text []byte, err error)
- func (s *LenString) MarshalText() (text []byte, err error)
- func (s *LenString) MaxLen() int
- func (s *LenString) MinLen() int
- func (s *LenString) ScanString(source string, validate bool) error
- func (s *LenString) SetString(str string) error
- func (s *LenString) String() string
- func (s *LenString) UnmarshalJSON(text []byte) error
- func (s *LenString) UnmarshalText(text []byte) error
- func (s *LenString) Validate() error
- type Set
- func (set Set[T]) Add(val T)
- func (set Set[T]) AddSet(other Set[T])
- func (set Set[T]) AddSlice(vals []T)
- func (set Set[T]) Clear()
- func (set Set[T]) Clone() Set[T]
- func (set Set[T]) Contains(val T) bool
- func (set Set[T]) ContainsAll(vals ...T) bool
- func (set Set[T]) ContainsAny(vals ...T) bool
- func (set Set[T]) ContainsSet(other Set[T]) bool
- func (set Set[T]) Delete(val T)
- func (set Set[T]) DeleteSet(other Set[T])
- func (set Set[T]) DeleteSlice(vals []T)
- func (set Set[T]) Difference(other Set[T]) Set[T]
- func (set Set[T]) Equal(other Set[T]) bool
- func (set Set[T]) GetOne() T
- func (set Set[T]) Intersection(other Set[T]) Set[T]
- func (set Set[T]) IsEmpty() bool
- func (set Set[T]) IsNull() bool
- func (set Set[T]) Len() int
- func (set Set[T]) Map(mapFunc func(T) (T, bool)) Set[T]
- func (set Set[T]) MarshalJSON() ([]byte, error)
- func (set Set[T]) Sorted() []T
- func (set Set[T]) String() string
- func (set Set[T]) Union(other Set[T]) Set[T]
- func (set *Set[T]) UnmarshalJSON(j []byte) error
- type StaticValidatErr
- type StaticValidator
- type ValidatErr
- type ValidatErrFunc
- type ValidatErrs
- type Validator
- type ValidatorAsValidatErr
- type ValidatorFunc
- type Validators
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidValue = errors.New("invalid value")
ErrInvalidValue means that a value is not valid, returned by Validate() and ValidatorAsValidatErr.Validate().
Functions ¶
func CanMarshalJSON ¶
CanMarshalJSON returns if a type can be marshalled as JSON
func DeepValidate ¶
DeepValidate validates all fields of a struct, all elements of a slice or array, and all values of a map by recursively calling Validate or Valid methods.
func ReduceSlice ¶
func ReflectCompare ¶
ReflectCompare compares two reflect.Values of the same type. The function panics if the types of a and b are not idential or not orderable. Orderable types are variantes of integers, floats, and strings.
func SetToRandomizedSlice ¶
func SetToSortedSlice ¶
func SliceContainsAll ¶
func SliceContainsAll[T comparable](outer []T, inner ...T) bool
SliceContainsAll returns true if outer contains all elements of inner.
func SliceContainsAny ¶
func SliceContainsAny[T comparable](outer []T, inner ...T) bool
SliceContainsAny returns true if outer contains any element of inner.
func TryValidate ¶
TryValidate returns an error and true if v implements ValidatErr or Validator and the methods ValidatErr.Validate() or Validator.Valid() indicate an invalid value. The error from ValidatErr.Validate() is returned directly, and ErrInvalidValue is returned if Validator.Valid() is false. If v does not implement ValidatErr or Validator then nil and false will be returned.
func Validate ¶
Validate returns an error if v implements ValidatErr or Validator and the methods ValidatErr.Validate() or Validator.Valid() indicate an invalid value. The error from ValidatErr.Validate() is returned directly, and ErrInvalidValue is returned if Validator.Valid() is false. If v does not implement ValidatErr or Validator then nil will be returned.
Types ¶
type KeyMutex ¶
type KeyMutex[T comparable] struct { // contains filtered or unexported fields }
KeyMutex manages a unique mutex for every locked key. The mutex for a key exists as long as there are any locks waiting to be unlocked. This is equivalent to declaring a mutex variable for every key, except that the key and the number of mutexes are dynamic.
type LenString ¶
type LenString struct {
// contains filtered or unexported fields
}
LenString holds a string together with a minimum and maximum length. Validate returns an error if the string length does not fit the minium-maxium length. LenString implements the encoding.UnmarshalText, json.Unmarshaler, and strfmt.StringAssignable interfaces that will do length validation.
func MustLenString ¶
MustLenString returns a LenString or panics on errors from Validate.
func NewLenString ¶
NewLenString returns a new LenString without validating it.
func (*LenString) MarshalJSON ¶
MarshalText implements the json.Marshaler interface
func (*LenString) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface
func (*LenString) ScanString ¶
ScanString tries to parse and assign the passed source string as value of the implementing type.
If validate is true, the source string is checked for validity before it is assigned to the type.
If validate is false and the source string can still be assigned in some non-normalized way it will be assigned without returning an error.
func (*LenString) String ¶
String returns the string or "<nil>". String implements the fmt.Stringer interface.
func (*LenString) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface
func (*LenString) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface
type Set ¶
func (Set[T]) ContainsAll ¶
func (Set[T]) ContainsAny ¶
func (Set[T]) ContainsSet ¶
func (Set[T]) DeleteSlice ¶
func (set Set[T]) DeleteSlice(vals []T)
func (Set[T]) Difference ¶
func (Set[T]) GetOne ¶
func (set Set[T]) GetOne() T
GetOne returns one element of the set or the default value for T if the set is empty.
func (Set[T]) Intersection ¶
func (Set[T]) IsNull ¶
IsNull implements the nullable.Nullable interface by returning true if the set is nil.
func (Set[T]) MarshalJSON ¶
MarshalJSON implements encoding/json.Marshaler by returning the JSON null value for an empty (null) string.
func (*Set[T]) UnmarshalJSON ¶
UnmarshalJSON implements encoding/json.Unmarshaler
type StaticValidatErr ¶
type StaticValidatErr struct {
Err error
}
StaticValidatErr implements the ValidatErr interface for a validation error value.
func (StaticValidatErr) Validate ¶
func (v StaticValidatErr) Validate() error
Validate returns an error if the data of the implementation is not valid.
type StaticValidator ¶
type StaticValidator bool
StaticValidator implements the Validator interface a bool validity value.
func (StaticValidator) Valid ¶
func (valid StaticValidator) Valid() bool
Valid returns if the data of the implementation is valid.
type ValidatErr ¶
type ValidatErr interface { // Validate returns an error if the data of the implementation is not valid. Validate() error }
ValidatErr can be implemented by types that can validate their data.
func CombinedValidatErr ¶
func CombinedValidatErr(validatErrs ...ValidatErr) ValidatErr
CombinedValidatErr creates a ValidatErr whose Validate method returns the first error from the passed validatErrs Validate methods or nil if none returned an error.
type ValidatErrFunc ¶
type ValidatErrFunc func() error
ValidatErrFunc implements the ValidatErr interface with a function.
func (ValidatErrFunc) Validate ¶
func (f ValidatErrFunc) Validate() error
Validate returns an error if the data of the implementation is not valid.
type ValidatErrs ¶
type ValidatErrs []ValidatErr
func (ValidatErrs) Validate ¶
func (v ValidatErrs) Validate() error
Validate returns an error if the data of the implementation is not valid.
type Validator ¶
type Validator interface { // Valid returns if the data of the implementation is valid. Valid() bool }
Validator can be implemented by types that can validate their data.
func CombinedValidator ¶
CombinedValidator creates a Validator whose Valid method returns false if any of the passed validators Valid methods returned false, else it returns true.
type ValidatorAsValidatErr ¶
type ValidatorAsValidatErr struct {
Validator
}
ValidatorAsValidatErr wraps a Validator as a ValidatErr, returning ErrInvalidValue when Validator.Valid() returns false.
func (ValidatorAsValidatErr) Validate ¶
func (v ValidatorAsValidatErr) Validate() error
type ValidatorFunc ¶
type ValidatorFunc func() bool
ValidatorFunc implements the Validator interface with a function.
func (ValidatorFunc) Valid ¶
func (f ValidatorFunc) Valid() bool
Valid returns if the data of the implementation is valid.
type Validators ¶
type Validators []Validator
func (Validators) Valid ¶
func (v Validators) Valid() bool
Valid returns if the data of the implementation is valid.