Files
eSliderandCursor c575341178 feat(go-config): multi-format codecs, envc CLI, fixtures, ASRs
- Module github.com/eslider/go-config with env/yaml/json/ini packages
- internal: source, keymap, merge, structconv, bytesutil
- cmd/envc: convert, get, merge
- docs/asr ASR-0001..0008, README/CHANGELOG/AGENTS refresh
- golangci-lint v2 config; tests + fixtures

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-02 14:04:01 +01:00

50 lines
984 B
Go

package env
import (
"strings"
)
// insertPath walks path inside root, creating intermediate nested maps as
// needed, and stores value at the leaf. First write wins for a given leaf key
// within a single source map.
func insertPath(root map[string]any, path []string, value string) {
current := root
last := len(path) - 1
for i, raw := range path {
k := strings.ToLower(raw)
if i == last {
if _, exists := current[k]; exists {
return
}
current[k] = value
return
}
next, ok := current[k].(map[string]any)
if !ok {
next = make(map[string]any)
current[k] = next
}
current = next
}
}
func nestedFromFlat(flat map[string]string, prefix string) map[string]any {
out := make(map[string]any)
for k, v := range flat {
name := k
if prefix != "" {
if !strings.HasPrefix(name, prefix) {
continue
}
name = name[len(prefix):]
if name == "" {
continue
}
}
insertPath(out, strings.Split(name, "_"), v)
}
return out
}