2024-02-15 22:47:56 +00:00
|
|
|
package config
|
2024-02-11 19:28:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2024-02-15 17:43:35 +00:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2024-02-11 19:28:00 +00:00
|
|
|
)
|
|
|
|
|
2024-02-16 13:21:13 +00:00
|
|
|
func GetEnvOrDefault(key, def string) string {
|
|
|
|
value := os.Getenv(key)
|
|
|
|
if value == "" {
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
2024-02-19 09:09:30 +00:00
|
|
|
func newViper() *viper.Viper {
|
|
|
|
v := viper.New()
|
|
|
|
v.SetConfigName("zdravko")
|
|
|
|
v.SetConfigType("yaml")
|
|
|
|
v.AddConfigPath("/etc/zdravko/")
|
|
|
|
v.AddConfigPath("$HOME/.zdravko")
|
|
|
|
v.AddConfigPath("$HOME/.config/zdravko")
|
|
|
|
v.AddConfigPath("$XDG_CONFIG_HOME/zdravko")
|
|
|
|
v.AddConfigPath(".")
|
|
|
|
return v
|
2024-02-11 19:28:00 +00:00
|
|
|
}
|