-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
68 lines (56 loc) · 1.17 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
package main
import (
"os"
"gopkg.in/yaml.v2"
)
type config struct {
DBFilename string `yaml:"db_filename"`
Threshold int `yaml:"threshold"`
AddTagName string `yaml:"add_tag_name"`
AddDetails bool `yaml:"add_details"`
NewOnly bool `yaml:"new_only"`
}
func readConfig(fn string) (*config, error) {
ret := &config{
DBFilename: "df-hashstore.db",
Threshold: 50,
}
_, err := os.Stat(fn)
if err != nil {
if os.IsNotExist(err) {
// just return default config
return ret, nil
}
return nil, err
}
file, err := os.Open(fn)
defer file.Close()
if err != nil {
return nil, err
}
parser := yaml.NewDecoder(file)
parser.SetStrict(true)
err = parser.Decode(&ret)
if err != nil {
return nil, err
}
return ret, nil
}
// HACK - read the host from the server config - this should be provided
// by the server itself
type serverConfig struct {
Host string `yaml:"host"`
}
func readServerConfig(fn string) (*serverConfig, error) {
ret := &serverConfig{}
file, err := os.Open(fn)
defer file.Close()
if err != nil {
return nil, err
}
parser := yaml.NewDecoder(file)
if err := parser.Decode(&ret); err != nil {
return nil, err
}
return ret, nil
}