package config import ( "log/slog" "os" "strings" "github.com/spf13/viper" ) func ConfigDir() string { env := os.Getenv("CONFIG_PATH") if env != "" { return env } return "." } func Init() { // Read global config viper.SetConfigName("config") viper.SetConfigType("yaml") viper.AddConfigPath(ConfigDir()) // Bind ENV viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() conf := &config{} if err := viper.ReadInConfig(); err != nil { // Dont generate config when using dev mode slog.Error("[Config] Can't read config!", "err", err) os.Exit(1) } if err := viper.Unmarshal(conf); err != nil { slog.Error("[Condig] Can't unmarshal config!", "err", err) os.Exit(1) } }