Refine some structs and handle cycle import

This commit is contained in:
Granty1
2020-04-05 09:18:25 +08:00
parent 6db275ca39
commit 1891c1bcbc
15 changed files with 146 additions and 293 deletions

30
server/core/config.go Normal file
View File

@@ -0,0 +1,30 @@
package core
import (
"fmt"
"gin-vue-admin/global"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
)
func init() {
v := viper.New()
v.SetConfigName("config") // 设置配置文件名 (不带后缀)
v.AddConfigPath("/") // 第一个搜索路径
v.SetConfigType("json")
err := v.ReadInConfig() // 搜索路径,并读取配置数据
if err != nil {
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 err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
fmt.Println(err)
}
})
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
fmt.Println(err)
}
global.GVA_VP = v
}