-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
62 lines (49 loc) · 1.23 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
package duckron
import "github.com/spf13/viper"
type config struct {
Database DatabaseConfig `yaml:"database"`
Alerts AlertsConfig `yaml:"alerts"`
}
type DatabaseConfig struct {
Type string `yaml:"type"`
Path string `yaml:"path"`
Snapshot SnapshotConfig `yaml:"snapshot"`
Retention RetentionConfig `yaml:"retention"`
}
type AlertsConfig struct {
Threshold Threshold `yaml:"threshold"`
}
type Threshold struct {
Ram float64 `yaml:"ram"`
Cpu float64 `yaml:"cpu"`
Disk float64 `yaml:"disk"`
}
type SnapshotConfig struct {
IntervalHours string `yaml:"intervalHours"`
Destination string `yaml:"destination"`
Format string `yaml:"format"`
}
type RetentionConfig struct {
IntervalHours string `yaml:"intervalHours"`
}
type ConfigReader struct {
Reader *viper.Viper
}
func NewConfigReader() *ConfigReader {
reader := viper.New()
reader.SetConfigName("duckron")
reader.AddConfigPath(".")
reader.SetConfigType("yaml")
return &ConfigReader{Reader: reader}
}
func (c *ConfigReader) Read() (*config, error) {
config := &config{}
err := c.Reader.ReadInConfig()
if err != nil {
return nil, err
}
if err := c.Reader.Unmarshal(config); err != nil {
return nil, err
}
return config, nil
}