validate

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Blank = &DefaultValidationRule{ruleName: "Blank",
		ruleErrorMsg: "should be blank",
		ruleFunc:     isBlank}

	NotBlank = &DefaultValidationRule{ruleName: "NotBlank",
		ruleErrorMsg: "should not be blank",
		ruleFunc: func(value any) (bool, error) {
			r, e := isBlank(value)
			return !r, e
		}}
)

Functions

func Validate

func Validate(value any, vRule ...ValidationRule) (bool, error)

Types

type DefaultValidationError

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

func (*DefaultValidationError) Error

func (v *DefaultValidationError) Error() string

func (*DefaultValidationError) String

func (v *DefaultValidationError) String() string

type DefaultValidationResult

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

func (*DefaultValidationResult) AddError

func (v *DefaultValidationResult) AddError(fieldName, errormsg string) *DefaultValidationResult

func (*DefaultValidationResult) Valid

func (v *DefaultValidationResult) Valid() bool

func (*DefaultValidationResult) ValidationErrors

func (v *DefaultValidationResult) ValidationErrors() []ValidationError

type DefaultValidationRule

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

func (*DefaultValidationRule) RuleErrorMsg

func (r *DefaultValidationRule) RuleErrorMsg() string

func (*DefaultValidationRule) RuleFunc

func (r *DefaultValidationRule) RuleFunc() ValidationFunc

func (*DefaultValidationRule) RuleName

func (r *DefaultValidationRule) RuleName() string

type ValidationBucket

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

func NewBucket

func NewBucket() *ValidationBucket

func (*ValidationBucket) Error

func (b *ValidationBucket) Error() error

func (*ValidationBucket) ErrorCount

func (b *ValidationBucket) ErrorCount() int

func (*ValidationBucket) IsValid

func (b *ValidationBucket) IsValid() bool

func (*ValidationBucket) Result

func (b *ValidationBucket) Result() ValidationResult

func (*ValidationBucket) Validate

func (b *ValidationBucket) Validate(propName string, value any, vRule ...ValidationRule) (bool, error)

type ValidationError

type ValidationError interface {
	String() string
	Error() string
}

type ValidationFunc

type ValidationFunc func(value any) (bool, error)

type ValidationResult

type ValidationResult interface {
	Valid() bool
	ValidationErrors() []ValidationError
}

type ValidationRule

type ValidationRule interface {
	RuleName() string
	RuleFunc() ValidationFunc
	RuleErrorMsg() string
}

func OneOfRule

func OneOfRule(values ...any) ValidationRule

func Range added in v0.3.1

func Range[K constraints.Ordered](from K, to K) ValidationRule

Range returns a validation rule that checks if the value is within the range.

func RegExRule

func RegExRule(pattern string) ValidationRule

type Validator

type Validator struct {
}

func NewValidator

func NewValidator() *Validator

Jump to

Keyboard shortcuts

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