Documentation
¶
Index ¶
- type Between
- type IsDate
- type IsEmail
- type IsMobile
- type IsNumber
- type IsString
- type Length
- type Matches
- type Required
- type Rule
- func NewBetween(min uint32, max uint32) (Rule, error)
- func NewIsDate() (Rule, error)
- func NewIsEmail() (Rule, error)
- func NewIsMobile() (Rule, error)
- func NewIsNumber() (Rule, error)
- func NewIsString() (Rule, error)
- func NewLength(min uint32, max uint32) (Rule, error)
- func NewMatches(options []interface{}) (Rule, error)
- func NewRequired() (Rule, error)
- type RuleType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Between ¶ added in v1.12.0
type Between struct {
// contains filtered or unexported fields
}
Between checks if the value is present or not
func (*Between) Config ¶ added in v1.12.0
Config returns a map with all custom configuration data for the rule
func (*Between) ErrorMessage ¶ added in v1.12.0
ErrorMessage returns a message indicating why the value is NOT valid
type IsDate ¶ added in v1.12.0
type IsDate struct{}
IsDate checks if the value is a valid date
func (*IsDate) Config ¶ added in v1.12.0
Config returns a map with all custom configuration data for the rule
func (*IsDate) ErrorMessage ¶ added in v1.12.0
ErrorMessage returns a message indicating why the value is NOT valid
type IsEmail ¶
type IsEmail struct{}
IsEmail checks if the value is present or not
func (*IsEmail) ErrorMessage ¶
ErrorMessage returns a message indicating why the value is NOT valid
type IsMobile ¶ added in v1.12.0
type IsMobile struct{}
IsMobile checks if the value is a valid mobile number
func (*IsMobile) Config ¶ added in v1.12.0
Config returns a map with all custom configuration data for the rule
func (*IsMobile) ErrorMessage ¶ added in v1.12.0
ErrorMessage returns a message indicating why the value is NOT valid
type IsNumber ¶ added in v1.12.0
type IsNumber struct{}
IsNumber checks if the value is type of string
func (*IsNumber) Config ¶ added in v1.12.0
Config returns a map with all custom configuration data for the rule
func (*IsNumber) ErrorMessage ¶ added in v1.12.0
ErrorMessage returns a message indicating why the value is NOT valid
type IsString ¶ added in v1.12.0
type IsString struct{}
IsString checks if the value is type of string
func (*IsString) Config ¶ added in v1.12.0
Config returns a map with all custom configuration data for the rule
func (*IsString) ErrorMessage ¶ added in v1.12.0
ErrorMessage returns a message indicating why the value is NOT valid
type Length ¶ added in v1.12.0
type Length struct {
// contains filtered or unexported fields
}
Length checks if the value is within a range
func (*Length) Config ¶ added in v1.12.0
Config returns a map with all custom configuration data for the rule
func (*Length) ErrorMessage ¶ added in v1.12.0
ErrorMessage returns a message indicating why the value is NOT valid
type Matches ¶ added in v1.12.0
type Matches struct {
// contains filtered or unexported fields
}
Matches checks if the value matches one of the values provided in a list/slice
func (*Matches) Config ¶ added in v1.12.0
Config returns a map with all custom configuration data for the rule
func (*Matches) ErrorMessage ¶ added in v1.12.0
ErrorMessage returns a message indicating why the value is NOT valid
type Required ¶
type Required struct{}
Required checks if the value is present or not
func (*Required) ErrorMessage ¶
ErrorMessage returns a message indicating why the value is NOT valid
type Rule ¶
type Rule interface { // Type defines the type of the rule. // It should be unique within the entire set of rules Type() *RuleType // Config returns a map with all custom configuration data for the rule Config() map[string]interface{} // IsValid checks whether the value is valid or not according to the rule. // Default value returned should be false. This means that logic should // check if the value is valid IsValid(value interface{}) bool // ErrorMessage returns a message indicating why the value is NOT valid ErrorMessage(fieldName string) string }
Rule defines a validation to check if a value is valid or not
func NewBetween ¶ added in v1.12.0
NewBetween creates an instance of Between
func NewIsMobile ¶ added in v1.12.0
NewIsEmailRule creates an instance of IsMobile
func NewIsNumber ¶ added in v1.12.0
NewIsNumber creates an instance of IsNumber
func NewIsString ¶ added in v1.12.0
NewIsString creates an instance of IsString
func NewMatches ¶ added in v1.12.0
NewMatches creates an instance of Matches
type RuleType ¶
type RuleType struct {
// contains filtered or unexported fields
}
RuleType defines the name of the rule. It should be unique within the entire set of rules
var ( // TypeBetween is the name for the between rule TypeBetween *RuleType = &RuleType{"BETWEEN"} // TypeIsDate is the name for the is date rule TypeIsDate *RuleType = &RuleType{"IS_DATE"} // TypeIsEmail is the name for the is email rule TypeIsEmail *RuleType = &RuleType{"IS_EMAIL"} // TypeIsMobile is the name for the is mobile rule TypeIsMobile *RuleType = &RuleType{"IS_MOBILE"} // TypeIsNumber is the name for the is number rule TypeIsNumber *RuleType = &RuleType{"IS_NUMBER"} // TypeIsString is the name for the is email rule TypeIsString *RuleType = &RuleType{"IS_STRING"} // TypeLength is the name for the length rule TypeLength *RuleType = &RuleType{"LENGTH"} // TypeMatches is the name for the matches rule TypeMatches *RuleType = &RuleType{"MATCHES"} // TypeRequired is the name for the required rule TypeRequired *RuleType = &RuleType{"REQUIRED"} )
func NewRuleType ¶
NewRuleType creates an instance of RuleType