Documentation ¶
Index ¶
- Variables
- func MustRegisterEqual(fn interface{})
- func RegisterEqual(fn interface{}) error
- type InvalidEqualFnError
- type IsDef
- func Is(name string, checker ValueValidator) IsDef
- func IsAny(of ...IsDef) IsDef
- func IsDeepEqual(to interface{}) IsDef
- func IsEqual(to interface{}) IsDef
- func IsEqualToTime(to time.Time) IsDef
- func IsIntGt(than int) IsDef
- func IsSliceOf(validator validator.Validator) IsDef
- func IsStringContaining(needle string) IsDef
- func IsStringMatching(regexp *regexp.Regexp) IsDef
- func IsUnique() IsDef
- func Optional(id IsDef) IsDef
- type UniqScopeTracker
- type ValueValidator
Constants ¶
This section is empty.
Variables ¶
var IsDuration = Is("is a duration", func(path llpath.Path, v interface{}) *llresult.Results { if _, ok := v.(time.Duration); ok { return llresult.ValidResult(path) } return llresult.SimpleResult( path, false, fmt.Sprintf("Expected a time.duration, got '%v' which is a %T", v, v), ) })
IsDuration tests that the given value is a duration.
var IsNil = Is("is nil", func(path llpath.Path, v interface{}) *llresult.Results { if v == nil { return llresult.ValidResult(path) } return llresult.SimpleResult( path, false, fmt.Sprintf("Value %#v is not nil", v), ) })
IsNil tests that a value is nil.
var IsNonEmptyString = Is("is a non-empty string", func(path llpath.Path, v interface{}) *llresult.Results { strV, errorResults := isStrCheck(path, v) if errorResults != nil { return errorResults } if len(strV) == 0 { return llresult.SimpleResult(path, false, "String '%s' should not be empty", strV) } return llresult.ValidResult(path) })
IsNonEmptyString checks that the given value is a string and has a length > 1.
var IsString = Is("is a string", func(path llpath.Path, v interface{}) *llresult.Results { _, errorResults := isStrCheck(path, v) if errorResults != nil { return errorResults } return llresult.ValidResult(path) })
IsString checks that the given value is a string.
var KeyMissing = IsDef{Name: "check key not present", CheckKeyMissing: true}
KeyMissing checks that the given key is not present defined.
var KeyPresent = IsDef{Name: "check key present"}
KeyPresent checks that the given key is in the map, even if it has a nil value.
Functions ¶
func MustRegisterEqual ¶
func MustRegisterEqual(fn interface{})
MustRegisterEqual is the panic-ing equivalent of RegisterEqual.
func RegisterEqual ¶
func RegisterEqual(fn interface{}) error
RegisterEqual takes a function of the form fn(v someType) IsDef and registers it to check equality for that type.
Types ¶
type InvalidEqualFnError ¶
type InvalidEqualFnError struct {
// contains filtered or unexported fields
}
InvalidEqualFnError is the error type returned by RegisterEqual when there is an issue with the given function.
func (InvalidEqualFnError) Error ¶
func (e InvalidEqualFnError) Error() string
type IsDef ¶
type IsDef struct { Name string Checker ValueValidator Optional bool CheckKeyMissing bool }
An IsDef defines the type of Check to do. Generally only Name and Checker are set. Optional and CheckKeyMissing are needed for weird checks like key presence.
func Is ¶
func Is(name string, checker ValueValidator) IsDef
Is creates a named IsDef with the given Checker.
func IsAny ¶
IsAny takes a variable number of IsDef's and combines them with a logical OR. If any single definition matches the key will be marked as valid.
func IsDeepEqual ¶
func IsDeepEqual(to interface{}) IsDef
IsDeepEqual checks equality using reflect.DeepEqual.
func IsEqual ¶
func IsEqual(to interface{}) IsDef
IsEqual tests that the given object is equal to the actual object.
func IsEqualToTime ¶
IsEqualToTime ensures that the actual value is the given time, regardless of zone.
func IsSliceOf ¶
IsSliceOf validates that the array at the given key is an array of objects all validatable via the given validator.Validator.
func IsStringContaining ¶
IsStringContaining validates that the the actual value contains the specified substring.
func IsStringMatching ¶
IsStringMatching checks whether a value matches the given regexp.
func IsUnique ¶
func IsUnique() IsDef
IsUnique instances are used in multiple spots, flagging a value as being in error if it's seen across invocations. To use it, assign IsUnique to a variable, then use that variable multiple times in a map[string]interface{}.
type UniqScopeTracker ¶
type UniqScopeTracker map[interface{}]string
UniqScopeTracker is represents the tracking data for invoking IsUniqueTo.
func ScopedIsUnique ¶
func ScopedIsUnique() UniqScopeTracker
ScopedIsUnique returns a new scope for uniqueness checks.
func (UniqScopeTracker) IsUniqueTo ¶
func (ust UniqScopeTracker) IsUniqueTo(namespace string) IsDef
IsUniqueTo validates that the given value is only ever seen within a single namespace.