mappath

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 2 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(root map[string]any, parts []string)

Delete removes the leaf at parts; missing paths are silently ignored.

func DeleteDotted

func DeleteDotted(root map[string]any, dotted string)

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

func Get(root map[string]any, parts ...string) (any, bool)

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 GetDotted

func GetDotted(root map[string]any, dotted string) (any, bool)

GetDotted is the convenience wrapper for "a.b.c" callers.

func Set

func Set(root map[string]any, parts []string, v any)

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).

func SetDotted

func SetDotted(root map[string]any, dotted string, v any)

SetDotted is the convenience wrapper for "a.b.c" callers.

func Split

func Split(dotted string) []string

Split splits a dotted path "a.b.c" into ["a", "b", "c"]. Empty path returns an empty slice (callers may treat that as "root").

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.

Jump to

Keyboard shortcuts

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