Documentation
¶
Index ¶
- type ArrayOptions
- type ArrayRange
- type Blank
- type Composite
- type Country
- type Currency
- type Date
- type Email
- type EqualTo
- type Field
- type GreaterOrEqual
- type GreaterThen
- type IsBool
- type IsFalse
- type IsFloat
- type IsFloat32
- type IsFloat64
- type IsInt
- type IsInt8
- type IsInt16
- type IsInt32
- type IsInt64
- type IsString
- type IsStruct
- type IsTrue
- type IsUint
- type IsUint8
- type IsUint16
- type IsUint32
- type IsUint64
- 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 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 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
¶
Click to show internal directories.
Click to hide internal directories.