rule

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Between

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

Between checks if the value is present or not

func (*Between) Config

func (r *Between) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*Between) ErrorMessage

func (r *Between) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*Between) IsValid

func (r *Between) IsValid(value interface{}) bool

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

func (*Between) Type

func (r *Between) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

type IsDate

type IsDate struct{}

IsDate checks if the value is a valid date

func (*IsDate) Config

func (r *IsDate) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*IsDate) ErrorMessage

func (r *IsDate) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*IsDate) IsValid

func (r *IsDate) IsValid(value interface{}) bool

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

func (*IsDate) Type

func (r *IsDate) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

type IsEmail

type IsEmail struct{}

IsEmail checks if the value is present or not

func (*IsEmail) Config

func (r *IsEmail) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*IsEmail) ErrorMessage

func (r *IsEmail) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*IsEmail) IsValid

func (r *IsEmail) IsValid(value interface{}) bool

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

func (*IsEmail) Type

func (r *IsEmail) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

type IsMobile

type IsMobile struct{}

IsMobile checks if the value is a valid mobile number

func (*IsMobile) Config

func (r *IsMobile) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*IsMobile) ErrorMessage

func (r *IsMobile) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*IsMobile) IsValid

func (r *IsMobile) IsValid(value interface{}) bool

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

func (*IsMobile) Type

func (r *IsMobile) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

type IsNumber

type IsNumber struct{}

IsNumber checks if the value is type of string

func (*IsNumber) Config

func (r *IsNumber) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*IsNumber) ErrorMessage

func (r *IsNumber) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*IsNumber) IsValid

func (r *IsNumber) IsValid(value interface{}) bool

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

func (*IsNumber) Type

func (r *IsNumber) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

type IsString

type IsString struct{}

IsString checks if the value is type of string

func (*IsString) Config

func (r *IsString) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*IsString) ErrorMessage

func (r *IsString) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*IsString) IsValid

func (r *IsString) IsValid(value interface{}) bool

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

func (*IsString) Type

func (r *IsString) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

type Length

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

Length checks if the value is within a range

func (*Length) Config

func (r *Length) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*Length) ErrorMessage

func (r *Length) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*Length) IsValid

func (r *Length) IsValid(value interface{}) bool

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

func (*Length) Type

func (r *Length) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

type Matches

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

func (r *Matches) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*Matches) ErrorMessage

func (r *Matches) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*Matches) IsValid

func (r *Matches) IsValid(value interface{}) bool

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

func (*Matches) Type

func (r *Matches) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

type Required

type Required struct{}

Required checks if the value is present or not

func (*Required) Config

func (r *Required) Config() map[string]interface{}

Config returns a map with all custom configuration data for the rule

func (*Required) ErrorMessage

func (r *Required) ErrorMessage(fieldName string) string

ErrorMessage returns a message indicating why the value is NOT valid

func (*Required) IsValid

func (r *Required) IsValid(value interface{}) bool

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

func (*Required) Type

func (r *Required) Type() *RuleType

Type defines the type of the rule. It should be unique within the entire set of rules

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

func NewBetween(min uint32, max uint32) (Rule, error)

NewBetween creates an instance of Between

func NewIsDate

func NewIsDate() (Rule, error)

NewIsDate creates an instance of IsDate

func NewIsEmail

func NewIsEmail() (Rule, error)

NewIsEmail creates an instance of IsEmail

func NewIsMobile

func NewIsMobile() (Rule, error)

NewIsEmailRule creates an instance of IsMobile

func NewIsNumber

func NewIsNumber() (Rule, error)

NewIsNumber creates an instance of IsNumber

func NewIsString

func NewIsString() (Rule, error)

NewIsString creates an instance of IsString

func NewLength

func NewLength(min uint32, max uint32) (Rule, error)

NewLength creates an instance of Length

func NewMatches

func NewMatches(options []interface{}) (Rule, error)

NewMatches creates an instance of Matches

func NewRequired

func NewRequired() (Rule, error)

NewRequired creates an instance of Required

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

func NewRuleType(name string) (*RuleType, error)

NewRuleType creates an instance of RuleType

func (*RuleType) IsZero

func (rt *RuleType) IsZero() bool

IsZero defines whether FieldType is empty

func (*RuleType) Name

func (rt *RuleType) Name() string

Name returns the name of the field type

func (*RuleType) String

func (rt *RuleType) String() string

String defines the string interface

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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