This commit is contained in:
Blizzard
2025-04-24 00:36:39 +08:00
commit 991f37b13a
8 changed files with 123 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package core
import (
"fmt"
"github.com/spf13/viper"
"sundynix-go/config"
)
func Viper() (cfg *config.Config) {
viper.SetConfigFile("config.yaml")
viper.SetConfigType("yaml")
viper.AddConfigPath("../")
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// Config file not found; ignore error if desired
fmt.Println("Config file not found")
} else {
// Config file was found but another error was produced
fmt.Println("Read config file error ")
}
}
//将所有值或特定值解组到结构、映射中
//反序列化所有配置项
if err := viper.Unmarshal(&cfg); err != nil {
fmt.Printf("unmarshal error %s", err)
return
}
return
}