Added ReadDefault for supreme laziness

This commit is contained in:
Chris Bednarski 2015-08-31 19:54:49 -07:00
parent 1936932406
commit ecfeba3ce6

View file

@ -56,7 +56,7 @@ func NewConfig() Config {
return config
}
// GetOpt returns the specified configuration value or "".
// Read returns the specified configuration value or "".
func (c *Config) Read(id string) string {
val, ok := c.Options[id]
if !ok {
@ -64,3 +64,13 @@ func (c *Config) Read(id string) string {
}
return val
}
// ReadDefault returns the specified configuration value, or the specified
// default value if none is set.
func (c *Config) ReadDefault(id string, defaultValue string) string {
val := c.Read(id)
if val != "" {
return val
}
return defaultValue
}