constraints

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: BSD-3-Clause Imports: 11 Imported by: 3

Documentation

Index

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

type ArrayRange struct {
	Min float64
	Max float64
}

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 Blank

type Blank struct{}

func (Blank) Validate

func (c Blank) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Blank{}
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

func (c Composite) Validate(value any) error

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 Country added in v1.1.0

type Country struct{}

func (Country) Validate added in v1.1.0

func (c Country) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Country{}
value := "CZ"
errs := validator.Validate(value, con)

type Currency

type Currency struct{}

func (Currency) Validate

func (c Currency) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Currency{}
value := "USD"
errs := validator.Validate(value, con)

type Date added in v1.0.4

type Date struct {
	Min      time.Time
	Max      time.Time
	Format   string
	AllowNil bool
}

func (Date) Validate added in v1.0.4

func (c Date) Validate(value any) error

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 Email

type Email struct{}

func (Email) Validate

func (c Email) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Email{}
errs := validator.Validate(value, con)

type EqualTo added in v1.0.5

type EqualTo struct {
	Value any
}

func (EqualTo) Validate added in v1.0.5

func (r EqualTo) Validate(value any) error

Validate function for validate value

Example:

con := constraints.EqualTo{
	Value: "master"
}
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

func (n Field) Validate(value any) error

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 IsBool

type IsBool struct{}

func (IsBool) Validate

func (c IsBool) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsBool{}
errs := validator.Validate(value, con)

type IsFalse

type IsFalse struct{}

func (IsFalse) Validate

func (c IsFalse) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsFalse{}
errs := validator.Validate(value, con)

type IsFloat added in v1.0.2

type IsFloat struct{}

func (IsFloat) Validate added in v1.0.2

func (c IsFloat) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsFloat{}
errs := validator.Validate(value, con)

type IsFloat32 added in v1.0.2

type IsFloat32 struct{}

func (IsFloat32) Validate added in v1.0.2

func (c IsFloat32) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsFloat32{}
errs := validator.Validate(value, con)

type IsFloat64 added in v1.0.2

type IsFloat64 struct{}

func (IsFloat64) Validate added in v1.0.2

func (c IsFloat64) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsFloat64{}
errs := validator.Validate(value, con)

type IsInt added in v1.0.2

type IsInt struct{}

func (IsInt) Validate added in v1.0.2

func (c IsInt) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsInt{}
errs := validator.Validate(value, con)

type IsInt8 added in v1.0.2

type IsInt8 struct{}

func (IsInt8) Validate added in v1.0.2

func (c IsInt8) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsInt8{}
errs := validator.Validate(value, con)

type IsInt16 added in v1.0.2

type IsInt16 struct{}

func (IsInt16) Validate added in v1.0.2

func (c IsInt16) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsInt16{}
errs := validator.Validate(value, con)

type IsInt32 added in v1.0.2

type IsInt32 struct{}

func (IsInt32) Validate added in v1.0.2

func (c IsInt32) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsInt32{}
errs := validator.Validate(value, con)

type IsInt64 added in v1.0.2

type IsInt64 struct{}

func (IsInt64) Validate added in v1.0.2

func (c IsInt64) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsInt64{}
errs := validator.Validate(value, con)

type IsString added in v1.0.2

type IsString struct{}

func (IsString) Validate added in v1.0.2

func (c IsString) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsString{}
errs := validator.Validate(value, con)

type IsStruct added in v1.0.2

type IsStruct struct{}

func (IsStruct) Validate added in v1.0.2

func (c IsStruct) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsStruct{}
errs := validator.Validate(value, con)

type IsTrue

type IsTrue struct{}

func (IsTrue) Validate

func (c IsTrue) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsTrue{}
errs := validator.Validate(value, con)

type IsUint added in v1.0.2

type IsUint struct{}

func (IsUint) Validate added in v1.0.2

func (c IsUint) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsUint{}
errs := validator.Validate(value, con)

type IsUint8 added in v1.0.2

type IsUint8 struct{}

func (IsUint8) Validate added in v1.0.2

func (c IsUint8) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsUint8{}
errs := validator.Validate(value, con)

type IsUint16 added in v1.0.2

type IsUint16 struct{}

func (IsUint16) Validate added in v1.0.2

func (c IsUint16) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsUint16{}
errs := validator.Validate(value, con)

type IsUint32 added in v1.0.2

type IsUint32 struct{}

func (IsUint32) Validate added in v1.0.2

func (c IsUint32) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsUint32{}
errs := validator.Validate(value, con)

type IsUint64 added in v1.0.2

type IsUint64 struct{}

func (IsUint64) Validate added in v1.0.2

func (c IsUint64) Validate(value any) error

Validate function for validate value

Example:

con := constraints.IsUint64{}
errs := validator.Validate(value, con)

type Language

type Language struct{}

func (Language) Validate

func (c Language) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Language{}
value := "en"
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

type Length struct {
	Min int
	Max int
}

func (Length) Validate added in v1.0.6

func (c Length) Validate(value any) error

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 LessThen added in v1.0.5

type LessThen struct {
	Value float64
}

func (LessThen) Validate added in v1.0.5

func (r LessThen) Validate(value any) error

Validate function for validate value

Example:

con := constraints.LessThen{
	Value: 35
}
errs := validator.Validate(value, con)

type Nil added in v1.0.2

type Nil struct{}

func (Nil) Validate added in v1.0.2

func (c Nil) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Nil{}
errs := validator.Validate(value, con)

type NotBlank

type NotBlank struct{}

func (NotBlank) Validate

func (c NotBlank) Validate(value any) error

Validate function for validate value

Example:

con := constraints.NotBlank{}
errs := validator.Validate(value, con)

type NotNil added in v1.0.2

type NotNil struct{}

func (NotNil) Validate added in v1.0.2

func (c NotNil) Validate(value any) error

Validate function for validate value

Example:

con := constraints.NotNil{}
errs := validator.Validate(value, con)

type Options added in v1.0.3

type Options struct {
	Options []any
}

func (Options) Validate added in v1.0.3

func (c Options) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Options{
	Options: []any{"option1", "option2", "option3", 42},
}

value := "option1"
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 Range added in v1.0.5

type Range struct {
	Min float64
	Max float64
}

func (Range) Validate added in v1.0.5

func (r Range) Validate(value any) error

Validate function for validate value

Example:

con := constrains.Range{
	Min: 5,
	Max: 20,
}

value := 7
errs := validator.Validate(value, con)

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)

type Required

type Required struct{}

func (Required) Validate

func (c Required) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Required{}
errs := validator.Validate(value, con)

type Struct added in v1.0.2

type Struct struct {
	Struct interface{}
}

func (Struct) Validate added in v1.0.2

func (c Struct) Validate(value any) error

Validate function for validate value

Example:

con := constraints.Struct{
	Struct: MyStruct{},
}

errs := validator.Validate(value, con)

type Url added in v1.0.5

type Url struct {
	AllowEmpty     bool
	AllowedSchemes []string
}

func (Url) Validate added in v1.0.5

func (c Url) Validate(value any) error

Validate function for validate value

Example:

v := constraints.Url{
	AllowEmpty:     false,
	AllowedSchemes: []string{"http", "https"},
}

value := "https://example.com"
errs := validator.Validate(value, v)

Jump to

Keyboard shortcuts

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