Documentation
¶
Overview ¶
Package mappath provides dotted-path helpers for map[string]any trees. It is the single source of truth for read/write/delete-by-path operations previously duplicated in transform/, provider/env, and providers/consul.
Index ¶
- func Delete(root map[string]any, parts []string)
- func DeleteDotted(root map[string]any, dotted string)
- func ExpandLabels(input any, opts LabelOptions) map[string]any
- func Get(root map[string]any, parts ...string) (any, bool)
- func GetDotted(root map[string]any, dotted string) (any, bool)
- func Set(root map[string]any, parts []string, v any)
- func SetDotted(root map[string]any, dotted string, v any)
- func Split(dotted string) []string
- type LabelOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteDotted ¶
DeleteDotted is the convenience wrapper for "a.b.c" callers.
func ExpandLabels ¶
func ExpandLabels(input any, opts LabelOptions) map[string]any
ExpandLabels reshapes a flat list / map of "dotted.key=value" labels into a nested map[string]any so the configuration tree can carry Traefik / Docker / K8s style annotations. Accepted input shapes:
- []string{"a.b=1", "a.c=2"} — Compose / docker CLI form
- []any{"a.b=1", "a.c=2"} — YAML-decoded form
- map[string]string{"a.b":"1","a.c":"2"}— Docker engine / K8s annotation form
- map[string]any{"a.b":"1","a.c":"2"} — already-decoded YAML map
Malformed entries (no '=' separator, empty key after prefix trim) are silently dropped, matching Traefik's lenient behavior. The result is a freshly allocated tree; callers may merge it into an existing root via pkg/merger.Deep.
func Get ¶
Get returns the value at parts (or root[parts[0]][parts[1]]...) and whether it was found. Intermediate non-map values short-circuit to (nil,false).
func Set ¶
Set writes v at parts, creating intermediate maps as needed. Existing non-map values along the path are silently overwritten by a fresh map (matches the legacy env/consul behavior).
Types ¶
type LabelOptions ¶
type LabelOptions struct {
// Prefix, when non-empty, restricts expansion to labels whose key starts
// with this prefix (e.g. "traefik."). Labels lacking the prefix are
// silently skipped.
Prefix string
// StripPrefix removes Prefix from each key before expansion. Has no
// effect when Prefix is empty.
StripPrefix bool
// Separator splits a flat key into nested segments. Default ".".
Separator string
// Coerce, when true, converts "true" / "false" / int-like / float-like
// values into their typed forms (matching pkg/provider env coercion).
// Default false: values are kept verbatim as strings, matching Traefik /
// Compose label semantics.
Coerce bool
}
LabelOptions controls how ExpandLabels reshapes Traefik / Docker / K8s style flat labels into a nested map[string]any.