js

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPath = errors.New("invalid path")

Functions

This section is empty.

Types

type ArrayIndex

type ArrayIndex int

ArrayIndex holds up array index value under Path.

func (ArrayIndex) IsIndex

func (a ArrayIndex) IsIndex() bool

IsIndex on ArrayIndex always returns true.

func (ArrayIndex) String

func (a ArrayIndex) String() string

String returns array index values converted into a string.

type Path

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

Path is generated by the validator and indicates how it reached the invalid value from the root element. Property path is denoted by dots, while array access is denoted by square brackets. For example, "book.keywords[0]" means that the violation occurred on the first element of array "keywords" in the "book" object.

Internally Path is a linked list. You can create a new path using WithProperty or WithIndex methods. Path should always be used as a pointer value. Nil value is a valid value that means that the property path is empty.

func NewPath

func NewPath(elements ...PathElement) *Path

NewPath creates a Path from the list of elements. If the list is empty nil will be returned. Nil value is a valid value that means that the property path is empty.

func PathFromAny

func PathFromAny(elements ...interface{}) (*Path, error)

func (*Path) Elements

func (path *Path) Elements() []PathElement

Elements returns property path as a slice of PathElement. It returns nil if property path is nil (empty).

func (*Path) Len

func (path *Path) Len() int

Len returns count of property path elements.

func (*Path) MarshalText

func (path *Path) MarshalText() (text []byte, err error)

MarshalText will marshal property path value to a string.

func (*Path) String

func (path *Path) String() string

String is used to format property path to a string.

func (*Path) With

func (path *Path) With(next *Path) *Path

With returns new Path with appended elements to the end of the list.

func (*Path) WithIndex

func (path *Path) WithIndex(index int) *Path

WithIndex returns new Path with appended ArrayIndex to the end of the list.

func (*Path) WithProperty

func (path *Path) WithProperty(name string) *Path

WithProperty returns new Path with appended PropertyName to the end of the list.

type PathElement

type PathElement interface {
	// IsIndex can be used to determine whether an element is a string (property name) or
	// an index array.
	IsIndex() bool
	fmt.Stringer
}

PathElement is a part of the Path.

type PropertyName

type PropertyName string

PropertyName holds up property name value under Path.

func (PropertyName) IsIndex

func (p PropertyName) IsIndex() bool

IsIndex on PropertyName always returns false.

func (PropertyName) String

func (p PropertyName) String() string

String returns property name as is.

Jump to

Keyboard shortcuts

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