-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
executable file
·73 lines (60 loc) · 1.56 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"log"
"os"
"strconv"
"time"
"gopkg.in/yaml.v2"
)
// Constants
const (
SERVER_STATUS_ACTIVE = 1
SERVER_STATUS_INACTIVE = 2
SERVER_STATUS_DISABLED = 6
)
// Global variables
var (
seerConfig SeerConfig
monitorInterval time.Duration
)
// SeerConfig - Configuration structure
type SeerConfig struct {
Debug bool `yaml:"debug"`
Port int `yaml:"port"`
Database int `yaml:"db"`
MonitorInterval int `yaml:"monitorInterval"`
Servers map[string]*RedisServerConfig `yaml:"servers"`
SelectionMode string `yaml:"selectionMode"`
Master string
}
// RedisServerConfig - Redis Server configuration structure
type RedisServerConfig struct {
Alias string `yaml:"alias"`
Host string `yaml:"host"`
Port int `yaml:"port"`
Enabled bool `yaml:"enabled"`
Status int
}
// LoadConfig - Load the configuration from ./config.yml
func loadConfig(configPath string) {
f, err := os.Open(configPath)
if err != nil {
log.Fatalln(err)
os.Exit(1)
}
defer f.Close()
decoder := yaml.NewDecoder(f)
err = decoder.Decode(&seerConfig)
if err != nil {
log.Fatalln(err)
os.Exit(1)
}
// Interval between monitoring commands
interval := strconv.Itoa(seerConfig.MonitorInterval) + "s"
monitorInterval, err = time.ParseDuration(interval)
if err != nil {
log.Printf("Invalid interval provided %s for the monitor. Error: %s\r\n", interval, err)
os.Exit(1)
return
}
}