-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathconfig.go
35 lines (28 loc) · 800 Bytes
/
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
package resqueExporter
import (
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
GuardIntervalMillis int64 `yaml:"guard_interval_millis"`
ResqueNamespace string `yaml:"resque_namespace"`
Redis *RedisConfig `yaml:"redis"`
}
type RedisConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Password string `yaml:"password"`
DB int64 `yaml:"db"`
}
func loadConfig(configPath string) (*Config, error) {
data, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("Failed to load config; path:<%s>, err:<%s>", configPath, err)
}
var config *Config
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("Failed to parse yaml; err:<%s>", err)
}
return config, nil
}