resourcepaths

package
v1.34.7 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package resourcepaths parses API and other resource paths.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// AllowWildcard indicates whether the parser should allow wildcard segments.
	AllowWildcard bool

	// AllowFallback indicates whether the parser should allow fallback segments.
	AllowFallback bool

	// PrefixSlash indicates whether the parser should require a leading slash
	// or require that it's not present
	PrefixSlash bool
}

type Path

type Path struct {
	StartPos token.Pos
	Segments []Segment
}

Path represents a parsed path.

func Parse

func Parse(errs *perr.List, startPos token.Pos, path string, options Options) (parsedPath *Path, ok bool)

Parse parses a slash-separated path into path segments.

strPos is the position of where the path string was found in the source code.

func (*Path) End

func (p *Path) End() token.Pos

func (*Path) HasFallback added in v1.16.1

func (p *Path) HasFallback() bool

HasFallback is true if the path contains a fallback segment.

func (*Path) NumParams

func (p *Path) NumParams() int

NumParams reports the number of parameterized (non-literal) segments in the path.

func (*Path) Params

func (p *Path) Params() []Segment

Params returns the segments that are not literals.

func (*Path) Pos

func (p *Path) Pos() token.Pos

func (*Path) String

func (p *Path) String() string

String returns the path's string representation.

func (*Path) ToProto

func (p *Path) ToProto() *meta.Path

type Segment

type Segment struct {
	Type      SegmentType
	Value     string // literal if Type == Literal; name of parameter otherwise
	ValueType schema.BuiltinKind
	StartPos  token.Pos
	EndPos    token.Pos
}

Segment represents a parsed path segment.

func (Segment) End

func (s Segment) End() token.Pos

func (Segment) Pos

func (s Segment) Pos() token.Pos

func (*Segment) String

func (s *Segment) String() string

type SegmentType

type SegmentType int

SegmentType represents the different types of path segments recognized by the parser.

const (
	// Literal is a literal string path segment.
	Literal SegmentType = iota
	// Param represents a single path segment of any (non-empty) value.
	Param
	// Wildcard represents zero or more path segments of any value.
	Wildcard
	// Fallback represents zero or more path segments of any value
	// that are lower priority than any other path.
	Fallback
)

type Set

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

Set tracks a set of paths, ensuring they are compatible with each other. The zero value is ready to use.

func NewSet

func NewSet() *Set

func (*Set) Add

func (s *Set) Add(errs *perr.List, method string, path *Path) (ok bool)

Add adds a path to the set of paths.

Jump to

Keyboard shortcuts

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