Provide config helpers for environment variables

Add GetenvWithDefault, IsEnvTrue, and IsEnvFalse helpers to Config.

Test: m -j checkbuild
Change-Id: Id855e5349115eb2a18b2e73cfd1bd84b5874ff93
This commit is contained in:
Colin Cross 2016-11-23 16:52:04 -08:00
parent bba99041db
commit 99d7c23006

View file

@ -291,6 +291,24 @@ func (c *config) Getenv(key string) string {
return val
}
func (c *config) GetenvWithDefault(key string, defaultValue string) string {
ret := c.Getenv(key)
if ret == "" {
return defaultValue
}
return ret
}
func (c *config) IsEnvTrue(key string) bool {
value := c.Getenv(key)
return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
}
func (c *config) IsEnvFalse(key string) bool {
value := c.Getenv(key)
return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
}
func (c *config) EnvDeps() map[string]string {
c.envLock.Lock()
c.envFrozen = true