diff --git a/envconf.go b/envconf.go index 61ae76c..6a27336 100644 --- a/envconf.go +++ b/envconf.go @@ -21,9 +21,11 @@ type cEntry struct { } type Config struct { - parsed bool - env map[string]cEntry - mapEnv map[string]map[string]string + parsed bool + env map[string]cEntry + mapEnv map[string]map[string]string + mapMapEnv map[string]map[string]map[string]string + mapMapMapEnv map[string]map[string]map[string]map[string]string } // NewConfig returns an envconf.Config that is used to read configuration from environment variables. @@ -34,6 +36,8 @@ func NewConfig() *Config { config.parsed = false config.env = make(map[string]cEntry) config.mapEnv = make(map[string]map[string]string) + config.mapMapEnv = make(map[string]map[string]map[string]string) + config.mapMapMapEnv = make(map[string]map[string]map[string]map[string]string) for _, v := range os.Environ() { splitted := strings.SplitN(v, "=", 2) @@ -54,8 +58,28 @@ func NewConfig() *Config { right := strings.Join(splitted[count:], "_") if len(config.mapEnv[left]) == 0 { config.mapEnv[left] = make(map[string]string) + config.mapMapEnv[left] = make(map[string]map[string]string) + config.mapMapMapEnv[left] = make(map[string]map[string]map[string]string) } config.mapEnv[left][right] = key + if count < len(splitted)-2 { + middle := splitted[count] + right = strings.Join(splitted[count+1:], "_") + if len(config.mapMapEnv[left][middle]) == 0 { + config.mapMapEnv[left][middle] = make(map[string]string) + config.mapMapMapEnv[left][middle] = make(map[string]map[string]string) + } + config.mapMapEnv[left][middle][right] = key + } + if count < len(splitted)-3 { + lmiddle := splitted[count] + rmiddle := splitted[count+1] + right = strings.Join(splitted[count+2:], "_") + if len(config.mapMapEnv[left][lmiddle][rmiddle]) == 0 { + config.mapMapMapEnv[left][lmiddle][rmiddle] = make(map[string]string) + } + config.mapMapMapEnv[left][lmiddle][rmiddle][right] = key + } } } }