Use env vars when config.yaml not exist
All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-02-18 16:47:11 +08:00
parent e8571492f0
commit 79fbbd1862

View File

@@ -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!")
}