remove empty map

This commit is contained in:
Roy Olav Purser 2022-03-27 14:53:46 +02:00
parent 7a72947737
commit 19fdcd7e05
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -55,29 +55,34 @@ func NewConfig() *Config {
if len(splitted) > 1 { if len(splitted) > 1 {
for count, _ := range splitted { for count, _ := range splitted {
if count < len(splitted)-3 { if count < len(splitted)-3 {
left := strings.Join(splitted[:count], "_") left := strings.Trim(strings.Join(splitted[:count], "_"), "_")
right := strings.Join(splitted[count:], "_") right := strings.Trim(strings.Join(splitted[count:], "_"), "_")
if len(config.mapEnv[left]) == 0 { if len(config.mapEnv[left]) == 0 {
config.mapEnv[left] = make(map[string]string) config.mapEnv[left] = make(map[string]string)
config.mapMapEnv[left] = make(map[string]map[string]string) config.mapMapEnv[left] = make(map[string]map[string]string)
config.mapMapMapEnv[left] = make(map[string]map[string]map[string]string) config.mapMapMapEnv[left] = make(map[string]map[string]map[string]string)
} }
if left != "" && right != "" {
config.mapEnv[left][right] = key config.mapEnv[left][right] = key
}
middle := splitted[count] middle := splitted[count]
right = strings.Join(splitted[count+1:], "_") right = strings.Trim(strings.Join(splitted[count+1:], "_"), "_")
if len(config.mapMapEnv[left][middle]) == 0 { if len(config.mapMapEnv[left][middle]) == 0 {
config.mapMapEnv[left][middle] = make(map[string]string) config.mapMapEnv[left][middle] = make(map[string]string)
config.mapMapMapEnv[left][middle] = make(map[string]map[string]string) config.mapMapMapEnv[left][middle] = make(map[string]map[string]string)
} }
if left != "" && middle != "" && right != "" {
config.mapMapEnv[left][middle][right] = key config.mapMapEnv[left][middle][right] = key
}
lmiddle := splitted[count] lmiddle := splitted[count]
rmiddle := splitted[count+1] rmiddle := splitted[count+1]
right = strings.Join(splitted[count+2:], "_") right = strings.Trim(strings.Join(splitted[count+2:], "_"), "_")
if len(config.mapMapEnv[left][lmiddle][rmiddle]) == 0 { if len(config.mapMapEnv[left][lmiddle][rmiddle]) == 0 {
config.mapMapMapEnv[left][lmiddle][rmiddle] = make(map[string]string) config.mapMapMapEnv[left][lmiddle][rmiddle] = make(map[string]string)
} }
if left != "" && lmiddle != "" && rmiddle != "" && right != "" {
config.mapMapMapEnv[left][lmiddle][rmiddle][right] = key config.mapMapMapEnv[left][lmiddle][rmiddle][right] = key
} }
} }
@ -85,6 +90,7 @@ func NewConfig() *Config {
} }
} }
} }
}
return config return config
} }