style: Up conf

This commit is contained in:
lejianwen
2025-02-07 15:58:13 +08:00
parent e549416d94
commit 829f8799dd
2 changed files with 35 additions and 31 deletions

View File

@@ -2,7 +2,6 @@ package config
import (
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"strings"
)
@@ -38,7 +37,7 @@ type Config struct {
Jwt Jwt
Rustdesk Rustdesk
Proxy Proxy
Ldap Ldap
Ldap Ldap
}
// Init 初始化配置
@@ -57,15 +56,19 @@ func Init(rowVal *Config, path string) *viper.Viper {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
v.WatchConfig()
v.OnConfigChange(func(e fsnotify.Event) {
//配置文件修改监听
fmt.Println("config file changed:", e.Name)
if err2 := v.Unmarshal(rowVal); err2 != nil {
fmt.Println(err2)
}
rowVal.Rustdesk.LoadKeyFile()
rowVal.Rustdesk.ParsePort()
})
/*
//监听配置修改没什么必要
v.OnConfigChange(func(e fsnotify.Event) {
//配置文件修改监听
fmt.Println("config file changed:", e.Name)
if err2 := v.Unmarshal(rowVal); err2 != nil {
fmt.Println(err2)
}
rowVal.Rustdesk.LoadKeyFile()
rowVal.Rustdesk.ParsePort()
})
*/
if err := v.Unmarshal(rowVal); err != nil {
fmt.Println(err)
}