1
0
Fork 0
mirror of https://github.com/spf13/viper synced 2025-08-11 10:37:50 +00:00

Get String Else Default

Adds a fallback for get string
This commit is contained in:
david-doit-intl 2021-04-09 10:01:12 +01:00 committed by david-doit-intl
commit c14dd080f9
No known key found for this signature in database
GPG key ID: 25156B60983F60EF

View file

@ -860,6 +860,16 @@ func (v *Viper) GetString(key string) string {
return cast.ToString(v.Get(key))
}
// GetStringElseDefault returns the value associated with the key as a string,
// else if the string is empty it will return the default value
func (v *Viper) GetStringElseDefault(key string, defaultValue string) string {
value := v.GetString(key)
if value == "" {
return defaultValue
}
return value
}
// GetBool returns the value associated with the key as a boolean.
func GetBool(key string) bool { return v.GetBool(key) }