path

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Field string      // 字段名
	Op    Operator    // 操作符
	Value interface{} // 值
}

Condition 表示匹配条件

type Navigator struct{}

Navigator 负责在 YAML 树中导航和查找节点

func (n *Navigator) Find(root *yaml.Node, path *Path) ([]*yaml.Node, error)

Find 根据路径查找所有匹配的节点 返回匹配的节点列表(因为可能有通配符)

type Operator

type Operator int
const (
	OpEqual Operator = iota // = 精确匹配
	OpRegex                 // = 正则匹配(值为 @pattern@)
)

type Path

type Path struct {
	Segments []*Segment
}

Path 表示解析后的完整路径

func Parse

func Parse(pathStr string) (*Path, error)

Parse 解析路径字符串 支持语法:

  • spec.template.spec
  • containers[*]
  • containers[0]
  • containers[name=foo]
  • env[?] (占位符,实际匹配由 where 条件决定)

type Segment

type Segment struct {
	Type     SegmentType
	Field    string    // 字段名,如 "spec"
	Selector *Selector // 选择器,如 [name=foo] 或 [*]
}

Segment 表示路径的一个片段

type SegmentType

type SegmentType int
const (
	SegmentTypeField SegmentType = iota // 普通字段访问
	SegmentTypeArray                    // 数组访问
)

type Selector

type Selector struct {
	Type      SelectorType
	Condition *Condition // 条件匹配
}

Selector 表示数组选择器

type SelectorType

type SelectorType int
const (
	SelectorTypeWildcard  SelectorType = iota // [*] 通配符
	SelectorTypeIndex                         // [0] 索引
	SelectorTypeCondition                     // [name=foo] 条件
)

Jump to

Keyboard shortcuts

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