vz

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 6 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// ErrIDFailedValidation is an error ID.
	ErrIDFailedValidation = errorz.ID("failed-validation")
)

Variables

This section is empty.

Functions

func IsValidatable

func IsValidatable(v interface{}) bool

IsValidatable returns true if the given struct implements at least one of Validator or SimpleValidator.

func MustRegisterValidator

func MustRegisterValidator(tag string, validator validator.Func)

MustRegisterValidator registers a validator.

func MustValidate

func MustValidate(v interface{})

MustValidate is like Validate but panics on error.

func MustValidateStruct

func MustValidateStruct(v interface{})

MustValidateStruct is like ValidateStruct, panics on error.

func NewErrFailedValidation

func NewErrFailedValidation(format string, fields map[string]interface{}, options ...errorz.Option) error

NewErrFailedValidation creates a new failed validation error.

func RegexpValidatorFactory

func RegexpValidatorFactory(regexp *regexp.Regexp) validator.Func

RegexpValidatorFactory creates a validator that matches a regexp.

func Validate

func Validate(v interface{}) error

Validate calls Valid and/or Validate if the given value implements SimpleValidator or Validator. Panics if the given value implements none of the two.

func ValidateStruct

func ValidateStruct(v interface{}) error

ValidateStruct validates a struct.

func WrapErrFailedValidation

func WrapErrFailedValidation(err error, options ...errorz.Option) error

WrapErrFailedValidation wraps an error as failed validation error.

Types

type SimpleValidator

type SimpleValidator interface {
	Valid() bool
}

SimpleValidator describes a type that can validate itself, returning only a "valid" bool.

type Validator

type Validator interface {
	Validate() error
}

Validator describes a type that can validate itself.

Jump to

Keyboard shortcuts

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