keypath

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package keypath provides the KeyPath type and utilities for working with hierarchical configuration key paths.

A KeyPath is a []string representing a hierarchical key. For example, "server/http/port" becomes []string{"server", "http", "port"}.

Constructors

Methods

KeyPath provides methods for common path operations: KeyPath.String, KeyPath.MakeString, KeyPath.Parent, [KeyPath.Last], KeyPath.Append, [KeyPath.Equal], [KeyPath.HasPrefix], [KeyPath.TrimPrefix], [KeyPath.Len], and [KeyPath.IsEmpty].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyPath

type KeyPath []string

KeyPath represents a hierarchical key.

For example, for the key "/server/http/port" it will look like []string{"server", "http", "port"}.

func NewKeyPath

func NewKeyPath(path string) KeyPath

NewKeyPath creates a KeyPath from a string, splitting it by "/" slash. This is the main way to create a path from a textual representation.

func NewKeyPathFromSegments

func NewKeyPathFromSegments(segments []string) KeyPath

NewKeyPathFromSegments creates a KeyPath from a slice of segments. This is useful when you already have segments as a slice and don't need string parsing.

func NewKeyPathWithDelim

func NewKeyPathWithDelim(path, delim string) KeyPath

NewKeyPathWithDelim creates a KeyPath from a string, splitting it by the given delimiter. All segments are preserved, including empty ones.

func (KeyPath) Append

func (p KeyPath) Append(segments ...string) KeyPath

Append adds new segment(s) to the path, returning a new KeyPath. The original path is not changed (immutability).

func (KeyPath) Equals

func (p KeyPath) Equals(other KeyPath) bool

Equals checks that two paths are completely identical.

func (KeyPath) HasEmptySegment

func (p KeyPath) HasEmptySegment() bool

HasEmptySegment returns true if the path contains any empty segment ("").

func (KeyPath) Leaf

func (p KeyPath) Leaf() string

Leaf returns the last segment of the path. If the path is empty, returns an empty string.

func (KeyPath) MakeString

func (p KeyPath) MakeString(delim string) string

MakeString returns a textual representation of the path with the given delimiter.

func (KeyPath) Match

func (p KeyPath) Match(pattern KeyPath) bool

Match checks whether the path matches a pattern using wildcards. A wildcard is "*", which matches any single segment. A double wildcard "**" matches zero or more segments. Pattern matches if it is a prefix of the path (pattern length <= path length). For example, pattern "a/*/c" matches path "a/b/c". Pattern "a/*/c" also matches path "a/b/c/d" (since pattern is prefix). Pattern "a/**/c" matches path "a/b/c", "a/x/y/c", and "a/c".

func (KeyPath) Parent

func (p KeyPath) Parent() KeyPath

Parent returns the parent path. If the path consists of one element or is empty, returns nil.

func (KeyPath) String

func (p KeyPath) String() string

String returns a textual representation of the path with slash ("/") as the delimiter.

Jump to

Keyboard shortcuts

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