MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / watchConfig

Function watchConfig

pkg/conf/parse.go:68–86  ·  view source on GitHub ↗

listening for profile updates

(obj interface{}, reloads ...func())

Source from the content-addressed store, hash-verified

66
67// listening for profile updates
68func watchConfig(obj interface{}, reloads ...func()) {
69 viper.WatchConfig()
70
71 // Note: OnConfigChange is called twice on Windows
72 viper.OnConfigChange(func(e fsnotify.Event) {
73 t := reflect.TypeOf(obj).Elem()
74 v := reflect.New(t)
75 reflect.ValueOf(obj).Elem().Set(v.Elem()) // reset object
76
77 err := viper.Unmarshal(obj)
78 if err != nil {
79 fmt.Println("viper.Unmarshal error: ", err)
80 } else {
81 for _, reload := range reloads {
82 reload()
83 }
84 }
85 })
86}
87
88// Show print configuration information (hide sensitive fields)
89func Show(obj interface{}, fields ...string) string {

Callers 1

ParseFunction · 0.85

Calls 3

PrintlnMethod · 0.80
SetMethod · 0.65
UnmarshalMethod · 0.65

Tested by

no test coverage detected