Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 (*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) MarshalText ¶
MarshalText will marshal property path value to a string.
func (*Path) WithIndex ¶
WithIndex returns new Path with appended ArrayIndex to the end of the list.
func (*Path) WithProperty ¶
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.