validate

package
v1.0.0-alpha5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMultipleOption would be returned by UndValidate and UndCheck
	// if input's `und` struct tags have multiple mutually exclusive options.
	ErrMultipleOption = undtag.ErrMultipleOption
	// ErrUnknownOption is an error value which will be returned by UndValidate and UndCheck
	// if an input has unknown options in `und` struct tag.
	ErrUnknownOption = undtag.ErrUnknownOption
	// ErrMalformedLen is an error which will be returned by UndValidate and UndCheck
	// if an input has malformed len option in `und` struct tag.
	ErrMalformedLen = undtag.ErrMalformedLen
	// ErrMalformedLen is an error which will be returned by UndValidate and UndCheck
	// if an input has malformed values option in `und` struct tag.
	ErrMalformedValues = undtag.ErrMalformedValues
)
View Source
var (
	// ErrNotStruct would be returned by UndValidate and UndCheck
	// if input is not a struct nor a pointer to a struct.
	ErrNotStruct = errors.New("not struct")
)

Functions

func AppendValidationErrorDot

func AppendValidationErrorDot(err error, selector string) error

func AppendValidationErrorIndex

func AppendValidationErrorIndex(err error, selector string) error

func ReportState

func ReportState(v any) string

func UndCheck

func UndCheck(s any) error

UndCheck checks whether s is correctly configured with `und` struct tag option without validating it.

func UndValidate

func UndValidate(s any) error

UndValidate validates whether s is compliant to the constraint placed by `und` struct tag.

UndValidate only accepts struct or pointer to struct.

Only fields whose struct tag contains `und`, and whose type is implementor of OptionLike, UndLike, ElasticLike, or array, slice, map whose value type are one of implementor, are validated.

Types

type ElasticLike

type ElasticLike = undtag.ElasticLike

type OptionLike

type OptionLike = undtag.OptionLike

type UndChecker

type UndChecker interface {
	UndCheck() error
}

UndChecker wraps the UndCheck method which is expected to be implemented on data container types like und.Und[T] and option.Option[T], etc.

UndCheck must checks if its internal data type conforms the constraint which UndValidate or UndCheck would checks.

type UndLike

type UndLike = undtag.UndLike

type UndValidator

type UndValidator interface {
	UndValidate() error
}

UndValidator wraps the UndValidate method.

UndValidate method is implemented on data container types, und.Und[T] and option.Option[T], etc. It only validates its underlying T's compliance for constraints placed by `und` struct tag options.

type ValidationError

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

func NewValidationError

func NewValidationError(err error) *ValidationError

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Pointer

func (e *ValidationError) Pointer() string

Pointer returns rfc6901 compliant json pointer

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

Jump to

Keyboard shortcuts

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