...

Package resourcename

import "go.einride.tech/aip/resourcename"
Overview
Index

Overview ▾

Package resourcename implements simple functions to manipulate UTF-8 encoded AIP resource names.

Constants

RevisionSeparator is the separator character used to separate resource IDs from revision IDs.

const RevisionSeparator = '@'

Wildcard is the resource name wildcard character "-".

const Wildcard = "-"

func Ancestor

func Ancestor(name, pattern string) (string, bool)

Ancestor extracts an ancestor from the provided name, using a pattern for the ancestor.

func ContainsWildcard

func ContainsWildcard(name string) bool

ContainsWildcard reports whether the specified resource name contains any wildcard segments.

func HasParent

func HasParent(name, parent string) bool

HasParent tests whether name has the specified parent. Wildcard segments (-) are considered. Resource names without revisions are considered parents of the same resource name with a revision.

func Join

func Join(elems ...string) string

Join combines resource names, separating them by slashes.

func Match

func Match(pattern, name string) bool

Match reports whether the specified resource name matches the specified resource name pattern.

func RangeParents

func RangeParents(name string, fn func(parent string) bool)

RangeParents iterates over all parents of the provided resource name. The iteration order is from root ancestor down to the closest parent. Collection segments are included in the iteration, to not require knowing the pattern. For full resource names, the service is omitted.

func Sprint

func Sprint(pattern string, variables ...string) string

Sprint formats resource name variables according to a pattern and returns the resulting string.

func Sscan

func Sscan(name, pattern string, variables ...*string) (err error)

Sscan scans a resource name, storing successive segments into successive variables as determined by the provided pattern.

func Validate

func Validate(name string) error

Validate that a resource name conforms to the restrictions outlined in AIP-122. See: https://google.aip.dev/122

func ValidatePattern

func ValidatePattern(pattern string) error

ValidatePattern that a resource name pattern conforms to the restrictions outlined in AIP-122. See: https://google.aip.dev/122

type Literal

Literal is the literal part of a resource name segment.

EBNF

Literal  = RESOURCE_ID | RevisionLiteral ;
RevisionLiteral = RESOURCE_ID "@" REVISION_ID ;
type Literal string

func (Literal) HasRevision

func (l Literal) HasRevision() bool

HasRevision returns true if the literal has a valid revision.

func (Literal) ResourceID

func (l Literal) ResourceID() string

ResourceID returns the literal's resource ID.

func (Literal) RevisionID

func (l Literal) RevisionID() string

RevisionID returns the literal's revision ID.

type Scanner

Scanner scans a resource name.

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

func (*Scanner) End

func (s *Scanner) End() int

End returns the end index (exclusive) of the current segment.

func (*Scanner) Full

func (s *Scanner) Full() bool

Full returns true if the scanner has detected a full resource name.

func (*Scanner) Init

func (s *Scanner) Init(name string)

Init initializes the scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() bool

Scan to the next segment.

func (*Scanner) Segment

func (s *Scanner) Segment() Segment

Segment returns the current segment.

func (*Scanner) ServiceName

func (s *Scanner) ServiceName() string

ServiceName returns the service name, when the scanner has detected a full resource name.

func (*Scanner) Start

func (s *Scanner) Start() int

Start returns the start index (inclusive) of the current segment.

type Segment

Segment is a segment of a resource name or a resource name pattern.

EBNF

Segment  = Literal | Variable ;
Variable = "{" Literal "}" ;
type Segment string

func (Segment) IsVariable

func (s Segment) IsVariable() bool

IsVariable reports whether the segment is a variable segment.

func (Segment) IsWildcard

func (s Segment) IsWildcard() bool

IsWildcard reports whether the segment is a wildcard.

func (Segment) Literal

func (s Segment) Literal() Literal

Literal returns the literal value of the segment. For variables, the literal value is the name of the variable.