zdravko/internal/config/config.go

28 lines
476 B
Go
Raw Normal View History

package config
import (
"os"
"github.com/spf13/viper"
)
2024-02-16 13:21:13 +00:00
func GetEnvOrDefault(key, def string) string {
value := os.Getenv(key)
if value == "" {
return def
}
return value
}
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
}