variable length hex
This commit is contained in:
parent
9733bb42a8
commit
02d36e3d69
@ -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)
|
||||
}
|
||||
|
12
envconf.go
12
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
|
||||
|
Loading…
Reference in New Issue
Block a user