verify data type for get
This commit is contained in:
parent
8d48099517
commit
4cd02d04a3
@ -13,6 +13,7 @@ const (
|
||||
)
|
||||
|
||||
type cValue struct {
|
||||
dtype DataType
|
||||
intval int64
|
||||
durval time.Duration
|
||||
boolval bool
|
||||
|
64
envconf.go
64
envconf.go
@ -104,65 +104,41 @@ func (c *Config) Status()(ok bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Config) GetInt(key string)(int64) {
|
||||
func (c *Config) getRaw(key string, dtype DataType)(val cValue) {
|
||||
val.dtype = TypeNone
|
||||
if c.parsed {
|
||||
upper := strings.ToUpper(key)
|
||||
entry, ok := c.env[upper]
|
||||
if ok {
|
||||
return entry.parsed.intval
|
||||
if ok && (entry.dtype == dtype) {
|
||||
return entry.parsed
|
||||
}
|
||||
}
|
||||
return 0
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Config) GetInt(key string)(int64) {
|
||||
val := c.getRaw(key, TypeInt)
|
||||
return val.intval
|
||||
}
|
||||
func (c *Config) GetMetric(key string)(int64) {
|
||||
if c.parsed {
|
||||
upper := strings.ToUpper(key)
|
||||
entry, ok := c.env[upper]
|
||||
if ok {
|
||||
return entry.parsed.intval
|
||||
}
|
||||
}
|
||||
return 0
|
||||
val := c.getRaw(key, TypeMetric)
|
||||
return val.intval
|
||||
}
|
||||
func (c *Config) GetDirectory(key string)(string) {
|
||||
if c.parsed {
|
||||
upper := strings.ToUpper(key)
|
||||
entry, ok := c.env[upper]
|
||||
if ok {
|
||||
return entry.parsed.strval
|
||||
}
|
||||
}
|
||||
return ""
|
||||
val := c.getRaw(key, TypeDirectory)
|
||||
return val.strval
|
||||
}
|
||||
func (c *Config) GetString(key string)(string) {
|
||||
if c.parsed {
|
||||
upper := strings.ToUpper(key)
|
||||
entry, ok := c.env[upper]
|
||||
if ok {
|
||||
return entry.parsed.strval
|
||||
}
|
||||
}
|
||||
return ""
|
||||
val := c.getRaw(key, TypeString)
|
||||
return val.strval
|
||||
}
|
||||
func (c *Config) GetDuration(key string)(time.Duration) {
|
||||
if c.parsed {
|
||||
upper := strings.ToUpper(key)
|
||||
entry, ok := c.env[upper]
|
||||
if ok {
|
||||
return entry.parsed.durval
|
||||
}
|
||||
}
|
||||
return time.Duration(0)
|
||||
val := c.getRaw(key, TypeDuration)
|
||||
return val.durval
|
||||
}
|
||||
func (c *Config) GetBool(key string)(bool) {
|
||||
if c.parsed {
|
||||
upper := strings.ToUpper(key)
|
||||
entry, ok := c.env[upper]
|
||||
if ok {
|
||||
return entry.parsed.boolval
|
||||
}
|
||||
}
|
||||
return false
|
||||
val := c.getRaw(key, TypeBool)
|
||||
return val.boolval
|
||||
}
|
||||
|
||||
func getFirstRune(str string)(rune) {
|
||||
|
Loading…
Reference in New Issue
Block a user