validators

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DateFormatValidator

type DateFormatValidator struct {
	// contains filtered or unexported fields
}

DateFormatValidator defines date format validator which validates date format depending on application's configuration

Data struct {
	 Date string `validate:"dateformat"`
}

func (*DateFormatValidator) Inject

func (v *DateFormatValidator) Inject(cfg *struct {
	DateFormat string `inject:"config:form.validator.dateFormat"`
})

Inject is method used to set all dependencies as local variables

func (*DateFormatValidator) ValidateField

func (v *DateFormatValidator) ValidateField(_ context.Context, fl validator.FieldLevel) bool

ValidateField validates string for right date format. Valid if string is empty or in right date format.

func (*DateFormatValidator) ValidatorName

func (v *DateFormatValidator) ValidatorName() string

ValidatorName defines tag name of date format validator

type MaximumAgeValidator

type MaximumAgeValidator struct {
	// contains filtered or unexported fields
}

MaximumAgeValidator defines maximum age validator which validates if passed date is after than desired years ago

Data struct {
	 Date string `validate:"maximumage=150"`
}

func (*MaximumAgeValidator) Inject

func (v *MaximumAgeValidator) Inject(cfg *struct {
	DateFormat string `inject:"config:form.validator.dateFormat"`
})

Inject is method used to set all dependencies as local variables

func (*MaximumAgeValidator) ValidateField

func (v *MaximumAgeValidator) ValidateField(_ context.Context, fl validator.FieldLevel) bool

ValidateField validates string in date format for maximum age. Valid if string is empty or in wrong date format or in date range.

func (*MaximumAgeValidator) ValidatorName

func (v *MaximumAgeValidator) ValidatorName() string

ValidatorName defines tag name of maximum age validator

type MinimumAgeValidator

type MinimumAgeValidator struct {
	// contains filtered or unexported fields
}

MinimumAgeValidator defines minimum age validator which validates if passed date is before than desired years ago

Data struct {
	 Date string `validate:"minimumage=18"`
}

func (*MinimumAgeValidator) Inject

func (v *MinimumAgeValidator) Inject(cfg *struct {
	DateFormat string `inject:"config:form.validator.dateFormat"`
})

Inject is method used to set all dependencies as local variables

func (*MinimumAgeValidator) ValidateField

func (v *MinimumAgeValidator) ValidateField(_ context.Context, fl validator.FieldLevel) bool

ValidateField validates string in date format for minimum age. Valid if string is empty or in wrong date format or in date range.

func (*MinimumAgeValidator) ValidatorName

func (v *MinimumAgeValidator) ValidatorName() string

ValidatorName defines tag name of minimum age validator

type RegexValidator

type RegexValidator struct {
	// contains filtered or unexported fields
}

RegexValidator defines regex validator. Name and regex pattern is passed to fresh instance during creation of validator.

validator := NewRegexValidator("postcode", "^[0-9]{5}$")

...

Data struct {
	 PostCode string `validate:"postcode"`
}

func NewRegexValidator

func NewRegexValidator(name string, regex string) *RegexValidator

NewRegexValidator creates new instance of RegexValidator by defining it's tag name and regex pattern

func (*RegexValidator) ValidateField

func (v *RegexValidator) ValidateField(_ context.Context, fl validator.FieldLevel) bool

ValidateField validates string if match right regex. Valid if string is empty or match defined regex pattern.

func (*RegexValidator) ValidatorName

func (v *RegexValidator) ValidatorName() string

ValidatorName defines tag name of regex validator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL