-
Notifications
You must be signed in to change notification settings - Fork 151
/
parameter.go
65 lines (51 loc) · 1.96 KB
/
parameter.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package parameter
import (
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/iotaledger/hive.go/parameter"
"github.com/iotaledger/hive.go/syncutils"
)
var (
// flags
configName = flag.StringP("config", "c", "config", "Filename of the config file without the file extension")
neighborsConfigName = flag.StringP("neighborsConfig", "n", "neighbors", "Filename of the neighbors config file without the file extension")
configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file")
// Viper
NodeConfig = viper.New()
NeighborsConfig = viper.New()
neighborsConfigHotReloadAllowed = true
neighborsConfigHotReloadLock syncutils.RWMutex
)
// FetchConfig fetches config values from a dir defined via CLI flag --config-dir (or the current working dir if not set).
//
// It automatically reads in a single config file starting with "config" (can be changed via the --config CLI flag)
// and ending with: .json, .toml, .yaml or .yml (in this sequence).
func FetchConfig(printConfig bool, ignoreSettingsAtPrint ...[]string) error {
// flags
err := parameter.LoadConfigFile(NodeConfig, *configDirPath, *configName, true, false)
if err != nil {
return err
}
parameter.PrintConfig(NodeConfig, ignoreSettingsAtPrint...)
err = parameter.LoadConfigFile(NeighborsConfig, *configDirPath, *neighborsConfigName, false, false)
if err != nil {
return err
}
parameter.PrintConfig(NeighborsConfig)
return nil
}
func AllowNeighborsConfigHotReload() {
neighborsConfigHotReloadLock.Lock()
defer neighborsConfigHotReloadLock.Unlock()
neighborsConfigHotReloadAllowed = true
}
func DenyNeighborsConfigHotReload() {
neighborsConfigHotReloadLock.Lock()
defer neighborsConfigHotReloadLock.Unlock()
neighborsConfigHotReloadAllowed = false
}
func IsNeighborsConfigHotReloadAllowed() bool {
neighborsConfigHotReloadLock.RLock()
defer neighborsConfigHotReloadLock.RUnlock()
return neighborsConfigHotReloadAllowed
}