rule

package
v1.8.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 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 NewIsEmail

func NewIsEmail() (Rule, error)

NewIsEmail creates an instance of IsEmail

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 (
	// IS_EMAIL is the name for the is email rule
	IS_EMAIL *RuleType = &RuleType{"IS_EMAIL"}
	// REQUIRED is the name for the required rule
	REQUIRED *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