From 79fbbd18620d354e9f28b594a727d3cd3fe5a5cf Mon Sep 17 00:00:00 2001 From: Asai Neko Date: Wed, 18 Feb 2026 16:47:11 +0800 Subject: [PATCH] Use env vars when config.yaml not exist Signed-off-by: Asai Neko --- config/config.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 33aaa9d..234b59a 100644 --- a/config/config.go +++ b/config/config.go @@ -26,11 +26,15 @@ func Init() { viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() - conf := &config{} if err := viper.ReadInConfig(); err != nil { - // Dont generate config when using dev mode - log.Fatalln("[Config] Can't read config!") + if _, ok := err.(viper.ConfigFileNotFoundError); ok { + log.Println("[Config] No config file found, using Env vars only.") + } else { + log.Fatalf("[Config] Fatal error reading config file: %s \n", err) + } } + + conf := &config{} if err := viper.Unmarshal(conf); err != nil { log.Fatalln("[Condig] Can't unmarshal config!") }