-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
executable file
·47 lines (43 loc) · 1.33 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* @Author: your name
* @Date: 2021-11-10 12:03:01
* @LastEditTime: 2021-11-10 12:03:53
* @LastEditors: your name
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: /tinycms/config/config.go
*/
package config
import (
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"github.com/tinybear1976/localsystem/logger"
"github.com/tinybear1976/tinycms/defines"
)
// func InitConfig() {
// viper.SetConfigName("config")
// viper.SetConfigType("yaml")
// viper.AddConfigPath(".")
// err := viper.ReadInConfig()
// if err != nil {
// panic(fmt.Errorf("fatal error config file: %s", err))
// }
// viper.WatchConfig()
// viper.OnConfigChange(func(e fsnotify.Event) {
// fmt.Println("Config file changed:", e.Name)
// })
// }
func InitSpecificConfig(onlyMFilename, fileType, filePath string) {
viper.SetConfigName(onlyMFilename)
viper.SetConfigType(fileType)
viper.AddConfigPath(filePath)
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("Config file changed:", e.Name)
logger.LogContainer[defines.LOG_APP].Warn("config file changed:" + e.Name)
})
}