validation

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder added in v0.1.0

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

func NewBuilder added in v0.1.0

func NewBuilder(v *Validation, field string, value interface{}) *Builder

NewBuilder creates a new Builder

func (*Builder) BetweenDate added in v0.1.0

func (v *Builder) BetweenDate(minDate, maxDate time.Time) *Builder

BetweenDate checks if the date is between the given dates

Has two parameters: minDate (time.Time), maxDate (time.Time)

func (*Builder) Custom added in v0.1.0

func (v *Builder) Custom(validator Validator) *Builder

Custom adds a custom validator to the validation

func (*Builder) IsAlphanumeric added in v0.1.0

func (v *Builder) IsAlphanumeric() *Builder

IsAlphanumeric checks if the data is alphanumeric excluding space

func (*Builder) IsEmail added in v0.1.0

func (v *Builder) IsEmail() *Builder

IsEmail checks if the data is a valid email address

func (*Builder) IsISO8601 added in v0.1.0

func (v *Builder) IsISO8601() *Builder

IsISO8601 checks if the data is a valid ISO8601 date

func (*Builder) IsISO8601Date added in v0.1.0

func (v *Builder) IsISO8601Date() *Builder

IsISO8601Date checks if the data is a valid ISO8601 date

func (*Builder) IsOnlyDigits added in v0.1.0

func (v *Builder) IsOnlyDigits() *Builder

IsOnlyDigits checks if the data contains only digits

func (*Builder) IsPhone added in v0.1.0

func (v *Builder) IsPhone() *Builder

IsPhone checks if the data is a valid phone number

func (*Builder) IsUUID added in v0.1.0

func (v *Builder) IsUUID() *Builder

IsUUID checks if the data is a valid UUID

func (*Builder) Length added in v0.1.0

func (v *Builder) Length(min, max int) *Builder

Length checks if the data is between min and max characters long

Has one parameter: length (int)

func (*Builder) Max added in v0.1.0

func (v *Builder) Max(max int64) *Builder

Max checks if the data is at most max

Has one parameter: max (int64)

func (*Builder) MaxCount added in v0.1.1

func (v *Builder) MaxCount(max int) *Builder

MaxCount checks if the slice/array/map has a maximum number of elements

Has one parameter: max (int)

func (*Builder) MaxDate added in v0.1.0

func (v *Builder) MaxDate(maxDate time.Time) *Builder

MaxDate checks if the date is before the given date

Has one parameter: maxDate (time.Time)

func (*Builder) MaxFloat added in v0.2.0

func (v *Builder) MaxFloat(max float64) *Builder

MaxFloat checks if the data is at most max

Has one parameter: max (float64)

func (*Builder) MaxInt added in v0.2.0

func (v *Builder) MaxInt(max int64) *Builder

MaxInt checks if the data is at most max

Has one parameter: max (int64)

func (*Builder) MaxLength added in v0.1.0

func (v *Builder) MaxLength(max int) *Builder

MaxLength checks if the data is at most max characters long

Has one parameter: max (int)

func (*Builder) MaxUint added in v0.2.0

func (v *Builder) MaxUint(max uint64) *Builder

MaxUint checks if the data is at most max

Has one parameter: max (uint64)

func (*Builder) Min added in v0.1.0

func (v *Builder) Min(min int64) *Builder

Min checks if the data is at least min

Has one parameter: min (int64)

func (*Builder) MinCount added in v0.1.1

func (v *Builder) MinCount(min int) *Builder

MinCount checks if the slice/array/map has a minimum number of elements

Has one parameter: min (int)

func (*Builder) MinDate added in v0.1.0

func (v *Builder) MinDate(minDate time.Time) *Builder

MinDate checks if the date is after the given date

Has one parameter: minDate (time.Time)

func (*Builder) MinFloat added in v0.2.0

func (v *Builder) MinFloat(min float64) *Builder

MinFloat checks if the data is at least min

Has one parameter: min (float64)

func (*Builder) MinInt added in v0.2.0

func (v *Builder) MinInt(min int64) *Builder

MinInt checks if the data is at least min

Has one parameter: min (int64)

func (*Builder) MinLength added in v0.1.0

func (v *Builder) MinLength(min int) *Builder

MinLength checks if the data is at least min characters long

Has one parameter: min (int)

func (*Builder) MinUint added in v0.2.0

func (v *Builder) MinUint(min uint64) *Builder

MinUint checks if the data is at least min

Has one parameter: min (uint64)

func (*Builder) Numeric added in v0.1.5

func (v *Builder) Numeric() *Builder

Numeric checks if the value is a number

func (*Builder) OneOf added in v0.1.0

func (v *Builder) OneOf(values ...string) *Builder

OneOf checks if the data is in the collection

Has one parameter named "collection" which is a slice of strings

func (*Builder) Range added in v0.1.0

func (v *Builder) Range(min, max int64) *Builder

Range checks if the data is between min and max

Has two parameters: min and max (int64)

func (*Builder) RangeFloat added in v0.2.0

func (v *Builder) RangeFloat(min, max float64) *Builder

RangeFloat checks if the data is between min and max

Has two parameters: min and max (float64)

func (*Builder) RangeInt added in v0.2.0

func (v *Builder) RangeInt(min, max int64) *Builder

RangeInt checks if the data is between min and max

Has two parameters: min and max (int64)

func (*Builder) RangeUint added in v0.2.0

func (v *Builder) RangeUint(min, max uint64) *Builder

RangeUint checks if the data is between min and max

Has two parameters: min and max (uint64)

func (*Builder) Required added in v0.1.0

func (v *Builder) Required() *Builder

add adds an error to the validation object Required checks if the data is nil or empty string

type Complex added in v0.1.1

type Complex interface {
	~complex64 | ~complex128
}

type Error

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

func NewError

func NewError(fieldErrors map[string]*FieldError) Error

func (Error) Error

func (e Error) Error() string

func (Error) Errors

func (e Error) Errors() map[string]*FieldError

type FieldError added in v0.0.2

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

func NewFieldError added in v0.0.2

func NewFieldError(field, message, tag string, value interface{}) *FieldError

func (*FieldError) Error added in v0.0.2

func (e *FieldError) Error() string

func (*FieldError) Field added in v0.0.2

func (e *FieldError) Field() string

func (*FieldError) HasParams added in v0.0.7

func (e *FieldError) HasParams() bool

func (*FieldError) Message added in v0.0.2

func (e *FieldError) Message() string

func (*FieldError) Param added in v0.0.2

func (e *FieldError) Param(key string) interface{}

func (*FieldError) Params added in v0.0.7

func (e *FieldError) Params() map[string]interface{}

func (*FieldError) SetMessage added in v0.0.2

func (e *FieldError) SetMessage(message string)

func (*FieldError) SetParam added in v0.0.2

func (e *FieldError) SetParam(key string, value interface{})

func (*FieldError) Tag added in v0.0.2

func (e *FieldError) Tag() string

func (*FieldError) Value added in v0.0.2

func (e *FieldError) Value() interface{}

type Float added in v0.1.1

type Float interface {
	~float32 | ~float64
}

type Integer added in v0.1.1

type Integer interface {
	Signed | Unsigned
}

type Number added in v0.1.1

type Number interface {
	Integer | Float
}

type Signed added in v0.1.1

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned added in v0.1.1

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Validation

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

func New

func New() *Validation

func (*Validation) Add

func (v *Validation) Add(field string, validations ...Validator)

func (*Validation) AddError added in v0.1.0

func (v *Validation) AddError(field string, err *FieldError)

func (*Validation) Builder added in v0.1.0

func (v *Validation) Builder(field string, value interface{}) *Builder

func (*Validation) Error

func (v *Validation) Error() error

type Validator added in v0.0.6

type Validator func(field string) *FieldError

func BetweenDate added in v0.1.0

func BetweenDate(date time.Time, minDate time.Time, maxDate time.Time) Validator

BetweenDate checks if the date is between the given dates

Has two parameters: minDate (time.Time), maxDate (time.Time)

func IsAlphanumeric added in v0.1.0

func IsAlphanumeric(value string) Validator

IsAlphanumeric checks if the data is alphanumeric excluding space

func IsEmail added in v0.1.0

func IsEmail(email string) Validator

IsEmail checks if the data is a valid email address

func IsISO8601 added in v0.1.0

func IsISO8601(date string) Validator

IsISO8601 checks if the data is a valid ISO8601 date

func IsISO8601Date added in v0.1.0

func IsISO8601Date(date string) Validator

IsISO8601Date checks if the data is a valid ISO8601 date

func IsOnlyDigits added in v0.1.0

func IsOnlyDigits(input string) Validator

IsOnlyDigits checks if the data contains only digits

func IsPhone added in v0.1.0

func IsPhone(phone string) Validator

IsPhone checks if the data is a valid phone number

func IsUUID added in v0.1.0

func IsUUID(input string) Validator

IsUUID checks if the data is a valid UUID

func Length added in v0.1.0

func Length(data string, min int, max int) Validator

Length checks if the data is between min and max characters long

Has one parameter: length (int)

func Max added in v0.1.0

func Max[T Number](data T, max T) Validator

Max checks if the data is at most max

Has one parameter: max (any number type, except complex)

func MaxCount added in v0.1.1

func MaxCount(array interface{}, max int) Validator

MaxCount checks if the length of the array/slice/map is less than or equal to the given number

Has one parameter: max (int)

func MaxDate added in v0.1.0

func MaxDate(date time.Time, maxDate time.Time) Validator

MaxDate checks if the date is before the given date

Has one parameter: maxDate (time.Time)

func MaxLength added in v0.1.0

func MaxLength(data string, max int) Validator

MaxLength checks if the data is at most max characters long

Has one parameter: max (int)

func Min added in v0.1.0

func Min[T Number](data T, min T) Validator

Min checks if the data is at least min

Has one parameter: min (any number type, except complex)

func MinCount added in v0.1.1

func MinCount(array interface{}, min int) Validator

MinCount checks if the length of the array/slice/map is greater than or equal to the given number

Has one parameter: min (int)

func MinDate added in v0.1.0

func MinDate(date time.Time, minDate time.Time) Validator

MinDate checks if the date is after the given date

Has one parameter: minDate (time.Time)

func MinLength added in v0.1.0

func MinLength(data string, min int) Validator

MinLength checks if the data is at least min characters long

Has one parameter: min (int)

func Numeric added in v0.1.5

func Numeric(value interface{}) Validator

Numeric checks if the given value is a number

func OneOf added in v0.1.0

func OneOf(item string, collection ...string) Validator

OneOf checks if the data is in the collection

Has one parameter named "collection" which is a slice of strings

func Range added in v0.1.0

func Range[T Number](data T, min T, max T) Validator

Range checks if the data is between min and max

Has two parameters: min (any number type, except complex), max (same type as min)

func Required added in v0.1.0

func Required(data interface{}) Validator

Required checks if the data is nil or empty string

Jump to

Keyboard shortcuts

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