validation

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 0 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data interface {
	// Get the value from the given key.
	Get(key string) (val any, exist bool)
	// Set the value for a given key.
	Set(key string, val any) error
}

type Errors

type Errors interface {
	// One gets the first error message for a given field.
	One(key ...string) string
	// Get gets all the error messages for a given field.
	Get(key string) map[string]string
	// All gets all the error messages.
	All() map[string]map[string]string
	// Has checks if there are any error messages for a given field.
	Has(key string) bool
}

type Option

type Option func(map[string]any)

type Rule

type Rule interface {
	// Signature set the unique signature of the rule.
	Signature() string
	// Passes determine if the validation rule passes.
	Passes(data Data, val any, options ...any) bool
	// Message gets the validation error message.
	Message() string
}

type Validation

type Validation interface {
	// Make create a new validator instance.
	Make(data any, rules map[string]string, options ...Option) (Validator, error)
	// AddRules add the custom rules.
	AddRules([]Rule) error
	// Rules get the custom rules.
	Rules() []Rule
}

type Validator

type Validator interface {
	// Bind the data to the validation.
	Bind(ptr any) error
	// Errors get the validation errors.
	Errors() Errors
	// Fails determine if the validation fails.
	Fails() bool
}

Jump to

Keyboard shortcuts

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