This commit is contained in:
张超
2024-11-07 10:09:53 +08:00
parent a96dff5804
commit feaff725ce
3 changed files with 45 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ import (
"log"
"time"
"github.com/fsnotify/fsnotify"
"github.com/go-ini/ini"
"github.com/spf13/viper"
)
@@ -81,6 +82,12 @@ func SetUp1() {
log.Fatalf("Error reading config file, %s", err)
}
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
// 配置文件发生变更之后会调用的回调函数
fmt.Println("Config file changed:", e.Name)
})
// 获取配置值
mysqlHost := viper.GetString("mysql.Host")
jwtSecretKey := viper.GetString("jwt.SecretKey")