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:
parent
52536944d5
commit
c14dd080f9
1 changed files with 10 additions and 0 deletions
10
viper.go
10
viper.go
|
@ -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) }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue