diff --git a/datatype.go b/datatype.go index 81a87e6..bf86e06 100644 --- a/datatype.go +++ b/datatype.go @@ -22,6 +22,10 @@ func FixedHex(size uint) DataType { return (DataType)(size<<16) | TypeHex } +func (dtype DataType) baseType() DataType { + return dtype & 0xffff +} + func (dtype DataType) typeAndSize() (DataType, uint) { return (dtype & 0xffff), uint(dtype >> 16) } diff --git a/envconf.go b/envconf.go index 6e2a538..c183e6e 100644 --- a/envconf.go +++ b/envconf.go @@ -287,7 +287,7 @@ func (c *Config) getRaw(key string, dtype DataType) (val cValue) { if c.parsed { key = cleanKey(key) entry, ok := c.env[key] - if ok && (entry.dtype == dtype) { + if ok && (entry.dtype.baseType() == dtype.baseType()) { return entry.parsed } } @@ -303,7 +303,7 @@ func (c *Config) getRawMap(key string, dtype DataType) (empty map[string]cValue) if ok { for k, v := range entries { - if (v.dtype == dtype) && (v.parsed.err == nil) { + if (v.dtype.baseType() == dtype.baseType()) && (v.parsed.err == nil) { retval[k] = v.parsed } else { return @@ -324,8 +324,8 @@ func (c *Config) GetInt(key string) int64 { // Returns the value of an environment variable. // If the variable is not defined as envconf.TypeHex the function will return []byte{}. -func (c *Config) GetHex(key string, size int) []byte { - val := c.getRaw(key, FixedHex(uint(size))) +func (c *Config) GetHex(key string) []byte { + val := c.getRaw(key, TypeHex) return val.binval } @@ -400,9 +400,9 @@ func (c *Config) GetMapBool(key string) (retval map[string]bool) { return } -func (c *Config) GetMapHex(key string, size int) (retval map[string][]byte) { +func (c *Config) GetMapHex(key string) (retval map[string][]byte) { retval = make(map[string][]byte) - for k, v := range c.getRawMap(key, FixedHex(uint(size))) { + for k, v := range c.getRawMap(key, TypeHex) { retval[k] = v.binval } return