Documentation
¶
Index ¶
Constants ¶
const ( UndTag = "und" // The field must be required(Some or Defined). // mutually exclusive to nullish, def, null, und. // UndTagValueRequired can be combined with len (there's no point though). UndTagValueRequired = "required" // The field must be nullish(None, Null, Undefined). // mutually exclusive to required, def, null, und. // UndTagValueNullish can be combined with len. UndTagValueNullish = "nullish" // The field is allowed to be Some or Defined. // can be combined with null, und or len. UndTagValueDef = "def" // The field is allowed to be None or Null. // can be combined with def, und or len. UndTagValueNull = "null" // The field is allowed to be None or Undefined. // can be combined with def, null or len. UndTagValueUnd = "und" // Only for elastic types. // // The value must be formatted as len==n, len>n, len>=n, len<n or len<=n, // where n is unsigned integer. // The field's length will be evaluated as (length) (comparison operator) (n), // e.g. if tag is len>12, field.Len() > 12 must return true. // // can be combined with other options. UndTagValueLen = "len" // Only for elastic types. // // The value must be formatted as values:nonnull. // // nonnull value means its internal value must not have null. UndTagValueValues = "values" )
Variables ¶
var ( // ErrNotStruct would be returned by ValidateUnd and CheckUnd // if input is not a struct nor a pointer to a struct. ErrNotStruct = errors.New("not struct") // ErrMultipleOption would be returned by ValidateUnd and CheckUnd // if input's `und` struct tags have multiple mutually exclusive options. ErrMultipleOption = errors.New("multiple option") // ErrUnknownOption is an error value which will be returned by ValidateUnd and CheckUnd // if an input has unknown options in `und` struct tag. ErrUnknownOption = errors.New("unknown option") // ErrMalformedLen is an error which will be returned by ValidateUnd and CheckUnd // if an input has malformed len option in `und` struct tag. ErrMalformedLen = errors.New("malformed len") // ErrMalformedLen is an error which will be returned by ValidateUnd and CheckUnd // if an input has malformed values option in `und` struct tag. ErrMalformedValues = errors.New("malformed values") )
Functions ¶
func CheckUnd ¶
CheckUnd checks whether s is correctly configured with `und` struct tag option without validating it.
func ValidateUnd ¶
ValidateUnd validates whether s is compliant to the constraint placed by `und` struct tag.
ValidateUnd only accepts struct or pointer to struct.
Only fields whose struct tag contains `und`, and whose type is implementor of OptionLike, UndLike or ElasticLike, are validated.
Types ¶
type CheckerUnd ¶
type CheckerUnd interface {
CheckUnd() error
}
CheckerUnd wraps the CheckUnd method which is expected to be implemented on data container types like und.Und[T] and option.Option[T], etc.
CheckUnd must checks if its internal data type conforms the constraint which ValidateUnd or CheckUnd would checks.
type ElasticLike ¶
type OptionLike ¶
type ValidatorUnd ¶
type ValidatorUnd interface {
ValidateUnd() error
}
ValidatorUnd wraps the ValidateUnd method.
ValidateUnd method is implemented on data container types, und.Und[T] and option.Option[T], etc. It only validates its underlying T's compliance for constraints placed by `und` struct tag options.