flattenAndMergeMap recursively flattens the given map into a map[string]bool of key paths (used as a set, easier to manipulate than a []string): - each path is merged into a single key string, delimited with v.keyDelim - if a path is shadowed by an earlier value in the initial shadow map, it is skip
(shadow map[string]bool, m map[string]any, prefix string)
| 1912 | // |
| 1913 | // The resulting set of paths is merged to the given shadow set at the same time. |
| 1914 | func (v *Viper) flattenAndMergeMap(shadow map[string]bool, m map[string]any, prefix string) map[string]bool { |
| 1915 | if shadow != nil && prefix != "" && shadow[prefix] { |
| 1916 | // prefix is shadowed => nothing more to flatten |
| 1917 | return shadow |
| 1918 | } |
| 1919 | if shadow == nil { |
| 1920 | shadow = make(map[string]bool) |
| 1921 | } |
| 1922 | |
| 1923 | var m2 map[string]any |
| 1924 | if prefix != "" { |
| 1925 | prefix += v.keyDelim |
| 1926 | } |
| 1927 | for k, val := range m { |
| 1928 | fullKey := prefix + k |
| 1929 | switch val := val.(type) { |
| 1930 | case map[string]any: |
| 1931 | m2 = val |
| 1932 | case map[any]any: |
| 1933 | m2 = cast.ToStringMap(val) |
| 1934 | default: |
| 1935 | // immediate value |
| 1936 | shadow[strings.ToLower(fullKey)] = true |
| 1937 | continue |
| 1938 | } |
| 1939 | // recursively merge to shadow map |
| 1940 | shadow = v.flattenAndMergeMap(shadow, m2, fullKey) |
| 1941 | } |
| 1942 | return shadow |
| 1943 | } |
| 1944 | |
| 1945 | // mergeFlatMap merges the given maps, excluding values of the second map |
| 1946 | // shadowed by values from the first map. |
no outgoing calls
no test coverage detected