Documentation
¶
Index ¶
- type ArrayOptions
- type ArrayRange
- type Blank
- type Composite
- type Contains
- type Country
- type Currency
- type Custom
- type Date
- type Email
- type EqualTo
- type Field
- type GreaterOrEqual
- type GreaterThen
- type HasPrefix
- type HasSuffix
- type IsBase32
- type IsBase64
- type IsBool
- type IsCamelCase
- type IsEven
- type IsFalse
- type IsFloat
- type IsFloat32
- type IsFloat64
- type IsHSLColor
- type IsHex
- type IsHexColor
- type IsIPv4
- type IsIPv6
- type IsInt
- type IsInt16
- type IsInt32
- type IsInt64
- type IsInt8
- type IsJSON
- type IsJWT
- type IsLowercase
- type IsMAC
- type IsMultipleOf
- type IsOdd
- type IsPascalCase
- type IsRGBColor
- type IsSHA256
- type IsString
- type IsStruct
- type IsTitleCase
- type IsTrue
- type IsUUID
- type IsUUIDv1
- type IsUUIDv2
- type IsUUIDv3
- type IsUUIDv4
- type IsUUIDv5
- type IsUint
- type IsUint16
- type IsUint32
- type IsUint64
- type IsUint8
- type IsUppercase
- type Language
- type LanguageWithRegion
- type Length
- type LessOrEqual
- type LessThen
- type Nil
- type NotBlank
- type NotNil
- type Options
- type PhoneNumber
- type Range
- type RegularExpression
- type Required
- type Struct
- type Url
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayOptions ¶ added in v1.0.3
type ArrayOptions struct {
Options []any
}
func (ArrayOptions) Validate ¶ added in v1.0.3
func (c ArrayOptions) Validate(value any) error
Validate function for validate value
Example:
con := constraints.Options{ Options: []any{"Red", "Green", "Blue", 100}, } values := []any{"Red", "Green", 100} errs := validator.Validate(values, con)
type ArrayRange ¶ added in v1.0.3
func (ArrayRange) Validate ¶ added in v1.0.3
func (c ArrayRange) Validate(value any) error
Validate function for validate value
Example:
con := constrains.ArrayRange{ Min: 5, Max: 20, } value := []any{5, 15, 19} errs := validator.Validate(value, con)
type Composite ¶ added in v1.0.6
type Composite struct {
Constraints []validator.Constraint
}
func (Composite) Validate ¶ added in v1.0.6
Validate function for validate value
Example:
nestedValidator := constraints.Field{ Constraints: map[string]validator.Constraint{ "Email": constraints.Composite{ Constraints: []validator.Constraint{ constraints.NotBlank{}, constraints.Length{Min: 5, Max: 50}, constraints.Email{}, }, }, "Name": constraints.Composite{ Constraints: []validator.Constraint{ constraints.NotBlank{}, constraints.Length{Min: 3, Max: 100}, }, }, }, } errs := validator.Validate(value, nestedValidator)
type Custom ¶ added in v1.3.0
Custom allows validating a value using a user-defined function. If the function returns an error, the constraint fails.
type Date ¶ added in v1.0.4
func (Date) Validate ¶ added in v1.0.4
Validate function for validate value
Example:
dateFormat := "2006-01-02" minDate, _ := time.Parse(dateFormat, "2023-01-01") maxDate, _ := time.Parse(dateFormat, "2023-12-31") con := constraints.Date{ Min: minDate, Max: maxDate, Format: dateFormat, } value := "01-05-2023" errs := validator.Validate(value, con)
type Field ¶ added in v1.0.6
type Field struct {
Constraints map[string]validator.Constraint
}
func (Field) Validate ¶ added in v1.0.6
Validate function for validate value
Example:
con := constraints.Field{ Constraints: map[string]validator.Constraint{ "Name": constraints.NotBlank{}, "Email": constraints.Email{}, "Address": constraints.Field{ Constraints: map[string]validator.Constraint{ "City": constraints.NotBlank{}, "Country": constraints.NotBlank{}, }, }, }, }
errs := validator.Validate(value, nestedValidator)
type GreaterOrEqual ¶ added in v1.0.5
type GreaterOrEqual struct {
Value float64
}
func (GreaterOrEqual) Validate ¶ added in v1.0.5
func (r GreaterOrEqual) Validate(value any) error
Validate function for validate value
Example:
con := constraints.GreaterOrEqual{ Value: 35 } errs := validator.Validate(value, con)
type GreaterThen ¶ added in v1.0.5
type GreaterThen struct {
Value float64
}
func (GreaterThen) Validate ¶ added in v1.0.5
func (r GreaterThen) Validate(value any) error
Validate function for validate value
Example:
con := constraints.GreaterThen{ Value: 35 } errs := validator.Validate(value, con)
type IsCamelCase ¶ added in v1.3.0
type IsCamelCase struct{}
func (IsCamelCase) Validate ¶ added in v1.3.0
func (c IsCamelCase) Validate(value any) error
type IsHSLColor ¶ added in v1.3.0
type IsHSLColor struct{}
func (IsHSLColor) Validate ¶ added in v1.3.0
func (c IsHSLColor) Validate(value any) error
type IsHexColor ¶ added in v1.3.0
type IsHexColor struct{}
func (IsHexColor) Validate ¶ added in v1.3.0
func (c IsHexColor) Validate(value any) error
type IsLowercase ¶ added in v1.3.0
type IsLowercase struct{}
func (IsLowercase) Validate ¶ added in v1.3.0
func (c IsLowercase) Validate(value any) error
type IsMultipleOf ¶ added in v1.3.0
type IsMultipleOf struct {
Divisor int
}
func (IsMultipleOf) Validate ¶ added in v1.3.0
func (c IsMultipleOf) Validate(value any) error
type IsPascalCase ¶ added in v1.3.0
type IsPascalCase struct{}
func (IsPascalCase) Validate ¶ added in v1.3.0
func (c IsPascalCase) Validate(value any) error
type IsRGBColor ¶ added in v1.3.0
type IsRGBColor struct{}
func (IsRGBColor) Validate ¶ added in v1.3.0
func (c IsRGBColor) Validate(value any) error
type IsTitleCase ¶ added in v1.3.0
type IsTitleCase struct{}
func (IsTitleCase) Validate ¶ added in v1.3.0
func (c IsTitleCase) Validate(value any) error
type IsUppercase ¶ added in v1.3.0
type IsUppercase struct{}
func (IsUppercase) Validate ¶ added in v1.3.0
func (c IsUppercase) Validate(value any) error
type LanguageWithRegion ¶
type LanguageWithRegion struct{}
func (LanguageWithRegion) Validate ¶
func (c LanguageWithRegion) Validate(value any) error
Validate function for validate value
con := constraints.Language{} value := "en-US" errs := validator.Validate(value, con)
type Length ¶ added in v1.0.6
func (Length) Validate ¶ added in v1.0.6
Validate function for validate value
Example:
con := constraints.Length{ Max: 4, } value := map[string]int{"a": 1, "b": 2, "c": 3} errs := validator.Validate(value, v) // Example 2 con := constraints.Length{ Min: 4, } value := "hello" errs := validator.Validate(value, v)
type LessOrEqual ¶ added in v1.0.5
type LessOrEqual struct {
Value float64
}
func (LessOrEqual) Validate ¶ added in v1.0.5
func (r LessOrEqual) Validate(value any) error
Validate function for validate value
Example:
con := constraints.LessOrEqual{ Value: 35 } errs := validator.Validate(value, con)
type PhoneNumber ¶ added in v1.0.6
type PhoneNumber struct { Format string // Format string, e.g., "(00420) 000 000 000" AllowEmpty bool // Allow empty values }
func (PhoneNumber) Validate ¶ added in v1.0.6
func (c PhoneNumber) Validate(value any) error
Validate function for validate value
Example:
con := constraints.PhoneNumber{Format: "(00420) 000 000 000"} value := "(00420) 123 456 789" errs := validator.Validate(value, v)
type RegularExpression ¶ added in v1.0.2
type RegularExpression struct {
Regexp string
}
func (RegularExpression) Validate ¶ added in v1.0.2
func (c RegularExpression) Validate(value any) error
Validate function for validate value
Example:
regExp := `^[a-z]{3}$` con := constraints.RegularExpression{ Regexp: regExp, } errs := validator.Validate(value, con)
Source Files
¶
- arrayRange.go
- base32.go
- base64.go
- blank.go
- bool.go
- color.go
- composite.go
- country.go
- currency.go
- custom.go
- date.go
- email.go
- equalTo.go
- field.go
- float.go
- greaterOrEqual.go
- greaterThen.go
- hex.go
- int.go
- ip.go
- json.go
- jwt.go
- language.go
- length.go
- lessOrEqual.go
- lessThen.go
- nil.go
- number.go
- options.go
- phoneNumber.go
- range.go
- regexp.go
- required.go
- sha256.go
- string.go
- struct.go
- text.go
- url.go
- uuid.go