Versions in this module Expand all Collapse all v1 v1.0.0 Jun 8, 2023 Changes in this version + var Empty = absentRule + var ErrDateInvalid = NewError("validation_date_invalid", "must be a valid date") + var ErrDateOutOfRange = NewError("validation_date_out_of_range", "the date is out of range") + var ErrEmpty = NewError("validation_empty", "must be blank") + var ErrInInvalid = NewError("validation_in_invalid", "must be a valid value") + var ErrKeyMissing = NewError("validation_key_missing", "required key is missing") + var ErrKeyUnexpected = NewError("validation_key_unexpected", "key not expected") + var ErrKeyWrongType = NewError("validation_key_wrong_type", "key not the correct type") + var ErrLengthEmptyRequired = NewError("validation_length_empty_required", "the value must be empty") + var ErrLengthInvalid = NewError("validation_length_invalid", "the length must be exactly {{.min}}") + var ErrLengthOutOfRange = NewError("validation_length_out_of_range", ...) + var ErrLengthTooLong = NewError("validation_length_too_long", "the length must be no more than {{.max}}") + var ErrLengthTooShort = NewError("validation_length_too_short", "the length must be no less than {{.min}}") + var ErrMatchInvalid = NewError("validation_match_invalid", "must be in a valid format") + var ErrMaxLessEqualThanRequired = NewError("validation_max_less_equal_than_required", ...) + var ErrMaxLessThanRequired = NewError("validation_max_less_than_required", "must be less than {{.threshold}}") + var ErrMinGreaterEqualThanRequired = NewError("validation_min_greater_equal_than_required", ...) + var ErrMinGreaterThanRequired = NewError("validation_min_greater_than_required", "must be greater than {{.threshold}}") + var ErrMultipleOfInvalid = NewError("validation_multiple_of_invalid", "must be multiple of {{.base}}") + var ErrNil = NewError("validation_nil", "must be blank") + var ErrNilOrNotEmpty = NewError("validation_nil_or_not_empty_required", "cannot be blank") + var ErrNotInInvalid = NewError("validation_not_in_invalid", "must not be in list") + var ErrNotMap = errors.New("only a map can be validated") + var ErrNotNilRequired = NewError("validation_not_nil_required", "is required") + var ErrRequired = NewError("validation_required", "cannot be blank") + var ErrStructPointer = errors.New("only a pointer to a struct can be validated") + var ErrorTag = "json" + var Nil = absentRule + var NilOrNotEmpty = RequiredRule + var NotNil = notNilRule + var Required = RequiredRule + var Skip = skipRule + func EnsureString(value interface{}) (string, error) + func Indirect(value interface{}) (interface{}, bool) + func IsEmpty(value interface{}) bool + func LengthOfValue(value interface{}) (int, error) + func StringOrBytes(value interface{}) (isString bool, str string, isBytes bool, bs []byte) + func ToFloat(value interface{}) (float64, error) + func ToInt(value interface{}) (int64, error) + func ToUint(value interface{}) (uint64, error) + func Validate(value interface{}, rules ...Rule) error + func ValidateStruct(structPtr interface{}, fields ...*FieldRules) error + func ValidateStructWithContext(ctx context.Context, structPtr interface{}, fields ...*FieldRules) error + func ValidateWithContext(ctx context.Context, value interface{}, rules ...Rule) error + type DateRule struct + func Date(layout string) DateRule + func (r DateRule) Error(message string) DateRule + func (r DateRule) ErrorObject(err Error) DateRule + func (r DateRule) Max(max time.Time) DateRule + func (r DateRule) Min(min time.Time) DateRule + func (r DateRule) RangeError(message string) DateRule + func (r DateRule) RangeErrorObject(err Error) DateRule + func (r DateRule) Validate(value interface{}) error + type EachRule struct + func Each(rules ...Rule) EachRule + func (r EachRule) Validate(value interface{}) error + func (r EachRule) ValidateWithContext(ctx context.Context, value interface{}) error + type ErrFieldNotFound int + func (e ErrFieldNotFound) Error() string + type ErrFieldPointer int + func (e ErrFieldPointer) Error() string + type Error interface + Code func() string + Error func() string + Message func() string + Params func() map[string]interface{} + SetMessage func(string) Error + SetParams func(map[string]interface{}) Error + func NewError(code, message string) Error + type ErrorObject struct + func (e ErrorObject) AddParam(name string, value interface{}) Error + func (e ErrorObject) Code() string + func (e ErrorObject) Error() string + func (e ErrorObject) Message() string + func (e ErrorObject) Params() map[string]interface{} + func (e ErrorObject) SetCode(code string) Error + func (e ErrorObject) SetMessage(message string) Error + func (e ErrorObject) SetParams(params map[string]interface{}) Error + type Errors map[string]error + func (es Errors) Error() string + func (es Errors) Filter() error + func (es Errors) Map() map[string]string + func (es Errors) MarshalJSON() ([]byte, error) + type FieldRules struct + func Field(fieldPtr interface{}, rules ...Rule) *FieldRules + type InRule struct + func In(values ...interface{}) InRule + func (r InRule) Error(message string) InRule + func (r InRule) ErrorObject(err Error) InRule + func (r InRule) Validate(value interface{}) error + type InternalError interface + InternalError func() error + func NewInternalError(err error) InternalError + type KeyRules struct + func Key(key interface{}, rules ...Rule) *KeyRules + func (r *KeyRules) Optional() *KeyRules + type LengthRule struct + func Length(min, max int) LengthRule + func RuneLength(min, max int) LengthRule + func (r LengthRule) Error(message string) LengthRule + func (r LengthRule) ErrorObject(err Error) LengthRule + func (r LengthRule) Validate(value interface{}) error + type MapRule struct + func Map(keys ...*KeyRules) MapRule + func (r MapRule) AllowExtraKeys() MapRule + func (r MapRule) Validate(m interface{}) error + func (r MapRule) ValidateWithContext(ctx context.Context, m interface{}) error + type MatchRule struct + func Match(re *regexp.Regexp) MatchRule + func (r MatchRule) Error(message string) MatchRule + func (r MatchRule) ErrorObject(err Error) MatchRule + func (r MatchRule) Validate(value interface{}) error + type MultipleOfRule struct + func MultipleOf(base interface{}) MultipleOfRule + func (r MultipleOfRule) Error(message string) MultipleOfRule + func (r MultipleOfRule) ErrorObject(err Error) MultipleOfRule + func (r MultipleOfRule) Validate(value interface{}) error + type NotInRule struct + func NotIn(values ...interface{}) NotInRule + func (r NotInRule) Error(message string) NotInRule + func (r NotInRule) ErrorObject(err Error) NotInRule + func (r NotInRule) Validate(value interface{}) error + type RequiredRule struct + func (r RequiredRule) Error(message string) RequiredRule + func (r RequiredRule) ErrorObject(err Error) RequiredRule + func (r RequiredRule) Validate(value interface{}) error + func (r RequiredRule) When(condition bool) RequiredRule + type Rule interface + Validate func(value interface{}) error + func By(f RuleFunc) Rule + func WithContext(f RuleWithContextFunc) Rule + type RuleFunc func(value interface{}) error + type RuleWithContext interface + ValidateWithContext func(ctx context.Context, value interface{}) error + type RuleWithContextFunc func(ctx context.Context, value interface{}) error + type StringRule struct + func NewStringRule(validator stringValidator, message string) StringRule + func NewStringRuleWithError(validator stringValidator, err Error) StringRule + func (r StringRule) Error(message string) StringRule + func (r StringRule) ErrorObject(err Error) StringRule + func (r StringRule) Validate(value interface{}) error + type ThresholdRule struct + func Max(max interface{}) ThresholdRule + func Min(min interface{}) ThresholdRule + func (r ThresholdRule) Error(message string) ThresholdRule + func (r ThresholdRule) ErrorObject(err Error) ThresholdRule + func (r ThresholdRule) Exclusive() ThresholdRule + func (r ThresholdRule) Validate(value interface{}) error + type Validatable interface + Validate func() error + type ValidatableWithContext interface + ValidateWithContext func(ctx context.Context) error + type WhenRule struct + func When(condition bool, rules ...Rule) WhenRule + func (r WhenRule) Else(rules ...Rule) WhenRule + func (r WhenRule) Validate(value interface{}) error + func (r WhenRule) ValidateWithContext(ctx context.Context, value interface{}) error