field

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

type Aggregate interface {
	error
	Errors() []error
	Is(error) bool
}

Aggregate represents an object that contains multiple errors, but does not necessarily have singular semantic meaning. The aggregate can be used with `errors.Is()` to check for the occurrence of a specific error type. Errors.As() is not supported, because the caller presumably cares about a specific error of potentially multiple that match the given type.

func NewAggregate

func NewAggregate(errlist []error) Aggregate

NewAggregate converts a slice of errors into an Aggregate interface, which is itself an implementation of the error interface. If the slice is empty, this returns nil. It will check if any of the element of input error list is nil, to avoid nil pointer panic when call Error().

type Error

type Error struct {
	Type     ErrorType
	Field    string
	BadValue interface{}
	Detail   string
}

Error is an implementation of the 'error' interface, which represents a field-level validation error.

func Invalid

func Invalid(field *Path, value interface{}, detail string) *Error

Invalid returns a *Error indicating "invalid value". This is used to report malformed values (e.g. failed regex match, too long, out of bounds).

func NotSupported

func NotSupported[T ~string](field *Path, value interface{}, validValues []T) *Error

NotSupported returns a *Error indicating "unsupported value". This is used to report unknown values for enumerated fields (e.g. a list of valid values).

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) ErrorBody

func (e *Error) ErrorBody() string

ErrorBody returns the error message without the field name. This is useful for building nice-looking higher-level error reporting.

type ErrorList

type ErrorList []*Error

ErrorList holds a set of Errors.

func (ErrorList) ToAggregate

func (list ErrorList) ToAggregate() Aggregate

ToAggregate converts the ErrorList into an Aggregate.

type ErrorType

type ErrorType string

ErrorType is a machine readable value providing more detail about why a field is invalid.

const (
	// ErrorTypeInvalid is used to report malformed values (e.g. failed regex
	// match, too long, out of bounds).  See Invalid().
	ErrorTypeInvalid ErrorType = "FieldValueInvalid"
	// ErrorTypeNotSupported is used to report unknown values for enumerated
	// fields (e.g. a list of valid values).  See NotSupported().
	ErrorTypeNotSupported ErrorType = "FieldValueNotSupported"
	// ErrorTypeInternal is used to report other errors that are not related
	// to user input.
	ErrorTypeInternal ErrorType = "InternalError"
)

func (ErrorType) String

func (t ErrorType) String() string

String converts a ErrorType into its corresponding canonical error message.

type Path

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

Path represents the path from some root to a particular field.

func NewPath

func NewPath(name string, moreNames ...string) *Path

NewPath creates a root Path object.

func ToPath

func ToPath(opts ...PathOption) *Path

ToPath produces *Path from a set of PathOption

func (*Path) Child

func (p *Path) Child(name string, moreNames ...string) *Path

Child creates a new Path that is a child of the method receiver.

func (*Path) Index

func (p *Path) Index(index int) *Path

Index indicates that the previous Path is to be subscripted by an int. This sets the same underlying value as Key.

func (*Path) Key

func (p *Path) Key(key string) *Path

Key indicates that the previous Path is to be subscripted by a string. This sets the same underlying value as Index.

func (*Path) Root

func (p *Path) Root() *Path

Root returns the root element of this Path.

func (*Path) String

func (p *Path) String() string

String produces a string representation of the Path.

type PathOption

type PathOption func(o *pathOptions)

PathOption modifies a pathOptions

func WithPath

func WithPath(p *Path) PathOption

WithPath generates a PathOption

Jump to

Keyboard shortcuts

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