2 Commits

Author SHA1 Message Date
712f3b65cf fix nil map 2022-01-15 18:52:45 +01:00
7b77ef35af fix nil map 2022-01-15 18:36:22 +01:00

View File

@ -48,6 +48,9 @@ func NewConfig() *Config {
} }
if unicode.IsLetter(getFirstRune(key)) { if unicode.IsLetter(getFirstRune(key)) {
if len(config.mapEnv[left]) == 0 {
config.mapEnv[left] = make(map[string]cEntry)
}
var entry cEntry var entry cEntry
entry.value = splitted[1] entry.value = splitted[1]
entry.dtype = TypeNone entry.dtype = TypeNone
@ -81,8 +84,8 @@ func (c *Config) Define(key string, dtype DataType) {
// Define the type of an environment variable. // Define the type of an environment variable.
// Variables without a defined type will be ignored by Parse. // Variables without a defined type will be ignored by Parse.
func (c *Config) DefineMap(key string, dtype DataType) { func (c *Config) DefineMap(key string, dtype DataType) {
upper := strings.ToUpper(key) key = cleanKey(key)
entries, ok := c.mapEnv[upper] entries, ok := c.mapEnv[key]
if ok { if ok {
for mapKey, entry := range entries { for mapKey, entry := range entries {
entry.dtype = dtype entry.dtype = dtype