MCPcopy Create free account
hub / github.com/auth0/auth0-cli / buildNestedMap

Function buildNestedMap

internal/cli/quickstarts.go:1608–1629  ·  view source on GitHub ↗

buildNestedMap converts a flat map with dot-delimited keys into a nested map, e.g. {"okta.oauth2.issuer": "x"} -> {"okta": {"oauth2": {"issuer": "x"}}}.

(flat map[string]string)

Source from the content-addressed store, hash-verified

1606// buildNestedMap converts a flat map with dot-delimited keys into a nested map,
1607// e.g. {"okta.oauth2.issuer": "x"} -> {"okta": {"oauth2": {"issuer": "x"}}}.
1608func buildNestedMap(flat map[string]string) map[string]interface{} {
1609 result := make(map[string]interface{})
1610 for key, value := range flat {
1611 parts := strings.Split(key, ".")
1612 current := result
1613 for i, part := range parts {
1614 if i == len(parts)-1 {
1615 if _, alreadyMap := current[part].(map[string]interface{}); !alreadyMap {
1616 current[part] = value
1617 }
1618 } else {
1619 next, ok := current[part].(map[string]interface{})
1620 if !ok {
1621 next = make(map[string]interface{})
1622 current[part] = next
1623 }
1624 current = next
1625 }
1626 }
1627 }
1628 return result
1629}
1630
1631// xmlEscape replaces XML/HTML special characters with their entity equivalents
1632// so that generated XML config files are well-formed even when values contain

Callers 2

TestBuildNestedMapFunction · 0.85
WriteQuickstartConfigMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestBuildNestedMapFunction · 0.68