path

package
v1.0.69 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	// Append adds path component to the end of path.
	// Builder state is cloned before adding component, so original builder instance is different from
	// returned one.
	Append(c ...Component) Builder

	// Build creates Path using current state.
	// Subsequent invocation of this function will always produce new Path instance, but with same content.
	Build() Path
}

Builder provides convenient way to construct Path using fluent builder pattern.

func NewBuilder

func NewBuilder(pc ...Component) Builder

NewBuilder creates new Builder

type Codec added in v1.0.67

type Codec interface {
	Parser() Parser
	Serializer() Serializer
}

Codec is interface that combines Parser and Serializer

type Component

type Component interface {
	// IsInsertAfterLast returns true if this path component points to non-existent item after last element in the list.
	// This is required by JSON pointer (rfc6901) during append to the end of list.
	IsInsertAfterLast() bool

	// IsNumeric returns true if name is numeric value according to rfc6901
	IsNumeric() bool

	// NumericValue gets number that points to array element with the zero-based index.
	// Only valid if IsNumeric returns true.
	NumericValue() int

	// Value returns canonical value of this component.
	Value() string
}

func AfterLast

func AfterLast() Component

func Numeric

func Numeric(val int) Component

func Simple

func Simple(value string) Component

type Parser

type Parser interface {
	// Parse parses source string into Path.
	// Any error encountered during parse is returned to caller.
	Parse(string) (Path, error)
	// MustParse parses source string into Path.
	// Any error encountered during parse will cause panic.
	MustParse(string) Path
}

Parser interface is implemented by different Path syntax parsers.

type Path

type Path interface {
	fmt.Stringer
	// Components returns copy of path components in this path
	Components() []Component

	// IsEmpty returns true if Path does not have any components.
	IsEmpty() bool

	// Last gets very last path Component, panics if path is empty.
	Last() Component
}

func ChildOf added in v1.0.66

func ChildOf(parent Path, cps ...Component) Path

ChildOf creates path based on parent Path with additional child path Components.

func ParentOf added in v1.0.66

func ParentOf(p Path) Path

ParentOf returns Path with last component stripped out. If given Path is empty, nil is returned.

type Serializer

type Serializer interface {
	// Serialize serializes path into lexical representation
	Serialize(Path) string
}

Serializer is interface that allows to serialize Path into lexical form

Jump to

Keyboard shortcuts

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