Documentation ¶
Index ¶
- Constants
- Variables
- func DataSetFromContext[T DataSet](ctx *Context) (T, bool)
- func ExtractDataSet[T any](ctx context.Context) (T, bool)
- func IsError(err error) (map[string][]string, bool)
- func SetTranslator(t Translator)
- func Validate(ctx context.Context, dataSet any, rules RuleSet) error
- func ValidateValue(ctx context.Context, value any, rules ...Rule) error
- type Callback
- type CallbackFunc
- type Compare
- type Context
- type DataSet
- type DummyTranslator
- type Each
- func (r *Each) SkipOnEmpty() *Each
- func (r *Each) SkipOnError() *Each
- func (r *Each) ValidateValue(ctx context.Context, value any) error
- func (r *Each) When(v WhenFunc) *Each
- func (r *Each) WithIncorrectInputMessage(incorrectInputMessage string) *Each
- func (r *Each) WithMessage(message string) *Each
- type Email
- type HumanText
- type IP
- type ImageMeta
- type ImageMetaData
- type InRange
- type JSON
- type Key
- type MSISDN
- type MatchRegularExpression
- func (r *MatchRegularExpression) SkipOnEmpty() *MatchRegularExpression
- func (r *MatchRegularExpression) SkipOnError() *MatchRegularExpression
- func (r *MatchRegularExpression) ValidateValue(_ context.Context, value any) error
- func (r *MatchRegularExpression) When(v WhenFunc) *MatchRegularExpression
- func (r *MatchRegularExpression) WithMessage(message string) *MatchRegularExpression
- type Nested
- type Number
- func (r *Number) SkipOnEmpty() *Number
- func (r *Number) SkipOnError() *Number
- func (r *Number) ValidateValue(_ context.Context, value any) error
- func (r *Number) When(v WhenFunc) *Number
- func (r *Number) WithNotNumberMessage(message string) *Number
- func (r *Number) WithTooBigMessage(message string) *Number
- func (r *Number) WithTooSmallMessage(message string) *Number
- type Required
- type Result
- func (s Result) AttributeErrorMessagesIndexedByPath(attribute string) map[string][]string
- func (s Result) CommonErrorMessages() []string
- func (s Result) Error() string
- func (s Result) ErrorMessagesIndexedByPath() map[string][]string
- func (s Result) Errors() []*ValidationError
- func (s Result) IsValid() bool
- func (s Result) WithError(errs ...*ValidationError) Result
- type Rule
- type RuleSet
- type RuleSkipEmpty
- type RuleSkipError
- type RuleWhen
- type Rules
- type StringLength
- func (r *StringLength) SkipOnEmpty() *StringLength
- func (r *StringLength) SkipOnError() *StringLength
- func (r *StringLength) ValidateValue(_ context.Context, value any) error
- func (r *StringLength) When(v WhenFunc) *StringLength
- func (r *StringLength) WithMessage(message string) *StringLength
- func (r *StringLength) WithTooLongMessage(message string) *StringLength
- func (r *StringLength) WithTooShortMessage(message string) *StringLength
- type Time
- func (r *Time) SkipOnEmpty() *Time
- func (r *Time) SkipOnError() *Time
- func (r *Time) ValidateValue(_ context.Context, value any) error
- func (r *Time) When(v WhenFunc) *Time
- func (r *Time) WithFormat(format string) *Time
- func (r *Time) WithFormatMessage(message string) *Time
- func (r *Time) WithMax(max TimeFunc) *Time
- func (r *Time) WithMessage(message string) *Time
- func (r *Time) WithMin(min TimeFunc) *Time
- func (r *Time) WithTooBigMessage(message string) *Time
- func (r *Time) WithTooSmallMessage(message string) *Time
- type TimeFunc
- type Translator
- type URL
- func (r *URL) SkipOnEmpty() *URL
- func (r *URL) SkipOnError() *URL
- func (r *URL) ValidateValue(_ context.Context, value any) error
- func (r *URL) When(v WhenFunc) *URL
- func (r *URL) WithEnableIDN() *URL
- func (r *URL) WithMessage(message string) *URL
- func (r *URL) WithValidScheme(scheme ...string) *URL
- type UUID
- func (r *UUID) SkipOnEmpty() *UUID
- func (r *UUID) SkipOnError() *UUID
- func (r *UUID) ValidateValue(_ context.Context, value any) error
- func (r *UUID) When(v WhenFunc) *UUID
- func (r *UUID) WithInvalidVersionMessage(message string) *UUID
- func (r *UUID) WithMessage(message string) *UUID
- func (r *UUID) WithVersion(version UUIDVersion) *UUID
- type UUIDVersion
- type UniqueValues
- type ValidationError
- type WhenFunc
Constants ¶
View Source
const ( ImageMimeTypePNG = "image/png" ImageMimeTypeJPG = "image/jpeg" ImageMimeTypeGIF = "image/gif" )
View Source
const AllowAnyURLSchema = "*"
View Source
const (
NestedShortcut = "*"
)
Variables ¶
Functions ¶
func DataSetFromContext ¶
func IsError ¶
IsError - проверяет на ошибку валидации и возвращает аттрибуты, где ключ равняется полю, а значения ошибкам валидации.
{ "client_id": [ "Value cannot be blank.", "Value is invalid." ] }
func SetTranslator ¶
func SetTranslator(t Translator)
Types ¶
type Callback ¶
type Callback[T any] struct { // contains filtered or unexported fields }
func NewCallback ¶
func NewCallback[T any](f CallbackFunc[T]) *Callback[T]
func (*Callback[T]) SkipOnEmpty ¶
func (*Callback[T]) SkipOnError ¶
func (*Callback[T]) ValidateValue ¶
type Compare ¶
type Compare struct {
// contains filtered or unexported fields
}
func NewCompare ¶
func (*Compare) SkipOnEmpty ¶
func (*Compare) SkipOnError ¶
func (*Compare) ValidateValue ¶
func (*Compare) WithMessage ¶
type Context ¶
func NewContext ¶
type DummyTranslator ¶
type DummyTranslator struct { }
type Each ¶
type Each struct {
// contains filtered or unexported fields
}
func (*Each) SkipOnEmpty ¶
func (*Each) SkipOnError ¶
func (*Each) WithIncorrectInputMessage ¶
func (*Each) WithMessage ¶
type HumanText ¶
type HumanText struct {
*MatchRegularExpression
}
func NewHumanText ¶
func NewHumanText() *HumanText
type IP ¶
type IP struct {
// contains filtered or unexported fields
}
func (*IP) SkipOnEmpty ¶
func (*IP) SkipOnError ¶
func (*IP) WithMessage ¶
type ImageMeta ¶
type ImageMeta struct {
// contains filtered or unexported fields
}
func NewImageMeta ¶
func NewImageMeta() *ImageMeta
func (*ImageMeta) SkipOnEmpty ¶
func (*ImageMeta) SkipOnError ¶
func (*ImageMeta) ValidateValue ¶
func (*ImageMeta) WithMessage ¶
type ImageMetaData ¶
type InRange ¶
type InRange struct {
// contains filtered or unexported fields
}
func NewInRange ¶
func (*InRange) SkipOnEmpty ¶
func (*InRange) SkipOnError ¶
func (*InRange) WithMessage ¶
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
func (*JSON) SkipOnEmpty ¶
func (*JSON) SkipOnError ¶
type MSISDN ¶
type MSISDN struct {
*MatchRegularExpression
}
type MatchRegularExpression ¶
type MatchRegularExpression struct {
// contains filtered or unexported fields
}
func NewMatchRegularExpression ¶
func NewMatchRegularExpression(pattern string) *MatchRegularExpression
func (*MatchRegularExpression) SkipOnEmpty ¶
func (r *MatchRegularExpression) SkipOnEmpty() *MatchRegularExpression
func (*MatchRegularExpression) SkipOnError ¶
func (r *MatchRegularExpression) SkipOnError() *MatchRegularExpression
func (*MatchRegularExpression) ValidateValue ¶
func (r *MatchRegularExpression) ValidateValue(_ context.Context, value any) error
func (*MatchRegularExpression) When ¶
func (r *MatchRegularExpression) When(v WhenFunc) *MatchRegularExpression
func (*MatchRegularExpression) WithMessage ¶
func (r *MatchRegularExpression) WithMessage(message string) *MatchRegularExpression
type Nested ¶
type Nested struct {
// contains filtered or unexported fields
}
func (*Nested) SkipOnEmpty ¶
func (*Nested) SkipOnError ¶
func (*Nested) WithMessage ¶
type Number ¶
type Number struct {
// contains filtered or unexported fields
}
func (*Number) SkipOnEmpty ¶
func (*Number) SkipOnError ¶
func (*Number) WithNotNumberMessage ¶
func (*Number) WithTooBigMessage ¶
func (*Number) WithTooSmallMessage ¶
type Required ¶
type Required struct {
// contains filtered or unexported fields
}
func NewRequired ¶
func NewRequired() *Required
func (*Required) SkipOnError ¶
func (*Required) ValidateValue ¶
func (*Required) WithAllowZeroValue ¶
deprecated: should be removed
func (*Required) WithMessage ¶
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
func (Result) AttributeErrorMessagesIndexedByPath ¶
func (Result) CommonErrorMessages ¶
func (Result) ErrorMessagesIndexedByPath ¶
func (Result) Errors ¶
func (s Result) Errors() []*ValidationError
func (Result) WithError ¶
func (s Result) WithError(errs ...*ValidationError) Result
type RuleSkipEmpty ¶
type RuleSkipEmpty interface {
// contains filtered or unexported methods
}
type RuleSkipError ¶
type RuleSkipError interface {
// contains filtered or unexported methods
}
type StringLength ¶
type StringLength struct {
// contains filtered or unexported fields
}
func NewStringLength ¶
func NewStringLength(min, max int) *StringLength
func (*StringLength) SkipOnEmpty ¶
func (r *StringLength) SkipOnEmpty() *StringLength
func (*StringLength) SkipOnError ¶
func (r *StringLength) SkipOnError() *StringLength
func (*StringLength) ValidateValue ¶
func (r *StringLength) ValidateValue(_ context.Context, value any) error
func (*StringLength) When ¶
func (r *StringLength) When(v WhenFunc) *StringLength
func (*StringLength) WithMessage ¶
func (r *StringLength) WithMessage(message string) *StringLength
func (*StringLength) WithTooLongMessage ¶
func (r *StringLength) WithTooLongMessage(message string) *StringLength
func (*StringLength) WithTooShortMessage ¶
func (r *StringLength) WithTooShortMessage(message string) *StringLength
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
func (*Time) SkipOnEmpty ¶
func (*Time) SkipOnError ¶
func (*Time) WithFormat ¶
func (*Time) WithFormatMessage ¶
func (*Time) WithMessage ¶
func (*Time) WithTooBigMessage ¶
func (*Time) WithTooSmallMessage ¶
type Translator ¶
type Translator interface { Translate( ctx context.Context, id string, params map[string]any, ) string }
var DefaultTranslator Translator = &DummyTranslator{}
type URL ¶
type URL struct {
// contains filtered or unexported fields
}
func (*URL) SkipOnEmpty ¶
func (*URL) SkipOnError ¶
func (*URL) WithEnableIDN ¶
func (*URL) WithMessage ¶
func (*URL) WithValidScheme ¶
type UUID ¶
type UUID struct {
// contains filtered or unexported fields
}
func (*UUID) SkipOnEmpty ¶
func (*UUID) SkipOnError ¶
func (*UUID) WithInvalidVersionMessage ¶
func (*UUID) WithMessage ¶
func (*UUID) WithVersion ¶
func (r *UUID) WithVersion(version UUIDVersion) *UUID
type UUIDVersion ¶
type UUIDVersion byte
const ( UUIDVersionV1 UUIDVersion = 1 UUIDVersionV3 UUIDVersion = 3 UUIDVersionV4 UUIDVersion = 4 UUIDVersionV5 UUIDVersion = 5 UUIDVersionV6 UUIDVersion = 6 UUIDVersionV7 UUIDVersion = 7 )
type UniqueValues ¶
type UniqueValues struct {
// contains filtered or unexported fields
}
func NewUniqueValues ¶
func NewUniqueValues() *UniqueValues
func (*UniqueValues) SkipOnEmpty ¶
func (r *UniqueValues) SkipOnEmpty() *UniqueValues
func (*UniqueValues) SkipOnError ¶
func (r *UniqueValues) SkipOnError() *UniqueValues
func (*UniqueValues) ValidateValue ¶
func (r *UniqueValues) ValidateValue(_ context.Context, value any) error
func (*UniqueValues) When ¶
func (r *UniqueValues) When(v WhenFunc) *UniqueValues
func (*UniqueValues) WithMessage ¶
func (r *UniqueValues) WithMessage(message string) *UniqueValues
type ValidationError ¶
func NewValidationError ¶
func NewValidationError(message string) *ValidationError
func (*ValidationError) Error ¶
func (v *ValidationError) Error() string
func (*ValidationError) WithParams ¶
func (v *ValidationError) WithParams(params map[string]any) *ValidationError
func (*ValidationError) WithValuePath ¶
func (v *ValidationError) WithValuePath(valuePath []string) *ValidationError
Source Files ¶
- basic.go
- callback.go
- compare.go
- context.go
- each.go
- email.go
- error.go
- human_text.go
- image_meta.go
- in_range.go
- interface.go
- ip.go
- json.go
- match_regular_expression.go
- msisdn.go
- nested.go
- number.go
- required.go
- result.go
- rules.go
- string_length.go
- time.go
- translator.go
- unique_values.go
- url.go
- uuid.go
- validator.go
Click to show internal directories.
Click to hide internal directories.