path

package
v0.0.0-...-5f1191e Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package path defines utilities to operate on translib path. TRanslib uses gnmi path syntax.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendElems

func AppendElems(path *gnmi.Path, elems ...string) *gnmi.Path

AppendElems appends one or more path elements to a gnmi.Path

func AppendPathStr

func AppendPathStr(path *gnmi.Path, suffix string) (*gnmi.Path, error)

AppendPathStr parses and appends a path string to the gnmi.Path object.

func Clone

func Clone(path *gnmi.Path) *gnmi.Path

Clone returns a clone of given gnmi.Path.

func Copy

func Copy(path *gnmi.Path) *gnmi.Path

Copy returns a new gnmi.Path using the elements of input gnmi.Path. Adding or removing elements from new path does not affect old one. But changes the element's contents will affect old path.

func Equals

func Equals(p1, p2 *gnmi.Path) bool

Equals returns true if path elements and they key/values are equal.

func GetElemAt

func GetElemAt(path *gnmi.Path, index int) string

GetElemAt returns the path element name at given index. Returns empty string if index is not valid.

func HasElemAt

func HasElemAt(path *gnmi.Path, index int, elem string) bool

HasElemAt checks if the path element at the given index has the string Returns true if string is found else false

func HasWildcardAtKey

func HasWildcardAtKey(p *gnmi.Path, index int) bool

HasWildcardAtKey checks if a gnmi.Path contains any wildcard key value ("*") at the given Elem index

func HasWildcardKey

func HasWildcardKey(p *gnmi.Path) bool

HasWildcardKey checks if a gnmi.Path contains any wildcard key value ("*").

func Len

func Len(path *gnmi.Path) int

Len returns number of elements in a gnmi.Path

func Matches

func Matches(path *gnmi.Path, template *gnmi.Path) bool

Matches checks if the path matches a template. Path must satisfy following conditions for a match:

  1. Should be of equal length or longer than template.
  2. Element names at each position should match.
  3. Keys at each postion should match -- should have same set of key names with same values. Wildcard value in the template matches any value of corresponding key in the path. But wildcard value in the path can only match with a wildcard value in template.

Examples: "AA/BB/CC" matches "AA/BB" "AA/BB[x=1][y=1]" matches "AA/BB[x=1][y=*]" "AA/BB[x=1][y=*]" matches "AA/BB[x=1][y=*]" "AA/BB[x=1]" does not match "AA/BB[x=1][y=*]" "AA/BB[x=*]" does not match "AA/BB[x=1]"

func MergeElemsAt

func MergeElemsAt(path *gnmi.Path, index int, elems ...string) int

MergeElemsAt merges new path elements at given path position. Returns number of elements merged.

func New

func New(pathStr string) (*gnmi.Path, error)

New returns gnmi.Path object for a path string. Returns nil with an error info for bad path value.

func NewPathValidator

func NewPathValidator(opts ...PathValidatorOpt) *pathValidator

NewPathValidator returns the PathValidator struct to validate the gnmi path and also add the missing module prefix and key names and wild card values in the gnmi path based on the given PathValidatorOpt

func RemoveModulePrefix

func RemoveModulePrefix(path *gnmi.Path)

RemoveModulePrefix strips out module prefixes from each element of a path.

func SetKey

func SetKey(elem *gnmi.PathElem, name, value string)

SetKey adds/updates a key value to the path element.

func SetKeyAt

func SetKeyAt(path *gnmi.Path, index int, name, value string)

SetKeyAt adds/updates a key value to the path element at given index.

func SplitLastElem

func SplitLastElem(p string) (prefix, last string)

SplitLastElem splits a string path into prefix & last path element

func StrHasWildcardKey

func StrHasWildcardKey(p string) bool

StrHasWildcardKey checks if gnmi path string has any wildcard key value. Equivalent of HasWildcardKey(ygot.StringToStructuredPath(p)); but checks for the wildcard without actually constructing a gnmi.Path.

func String

func String(path *gnmi.Path) string

String returns gnmi.Path as a string. Returns empty string if the path is not valid.

func SubPath

func SubPath(path *gnmi.Path, startIndex, endIndex int) *gnmi.Path

SubPath creates a new gnmi.Path having path elements from given start and end indices.

Types

type AddWildcardKeys

type AddWildcardKeys struct{}

AddWildcardKeys is an PathValidator option that indicates that the missing wild card keys in the given gnmi path will be added during the path validation

func (*AddWildcardKeys) IsPathValidatorOpt

func (*AddWildcardKeys) IsPathValidatorOpt()

IsPathValidatorOpt marks AddWildcardKeys as a valid PathValidatorOpt.

type AppendModulePrefix

type AppendModulePrefix struct{}

AppendModulePrefix is an PathValidator option that indicates that the missing module prefix in the given gnmi path will be added during the path validation

func (*AppendModulePrefix) IsPathValidatorOpt

func (*AppendModulePrefix) IsPathValidatorOpt()

IsPathValidatorOpt marks AppendModulePrefix as a valid PathValidatorOpt.

type IgnoreKeyValidation

type IgnoreKeyValidation struct{}

IgnoreKeyValidation is an PathValidator option to indicate the validator to ignore the key validation in the given gnmi path during the path validation

func (*IgnoreKeyValidation) IsPathValidatorOpt

func (*IgnoreKeyValidation) IsPathValidatorOpt()

IsPathValidatorOpt marks IgnoreKeyValidation as a valid PathValidatorOpt.

type PathValidatorOpt

type PathValidatorOpt interface {
	IsPathValidatorOpt()
}

PathValidatorOpt is an interface used for any option to be supplied

Jump to

Keyboard shortcuts

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