-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
68 lines (59 loc) · 1.14 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 flagstate
import (
"github.com/go-yaml/yaml"
"io/ioutil"
"time"
)
type Duration struct {
Value time.Duration
}
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
parsed, err := time.ParseDuration(s)
if err != nil {
return err
}
d.Value = parsed
return nil
}
type Config struct {
Registry struct {
Url string
PublicUrl string `yaml:"public_url"`
}
Components struct {
WebUI bool `yaml:"web_ui"`
AssertEndpoint bool `yaml:"assert_endpoint"`
}
Events struct {
Token string
}
Database struct {
Postgres struct {
Url string
}
}
Cache struct {
MaxAgeIndex Duration `yaml:"max_age_index"`
MaxAgeHtml Duration `yaml:"max_age_html"`
}
Interval struct {
FetchAll Duration `yaml:"fetch_all"`
GarbageCollect Duration `yaml:"garbage_collect"`
}
}
func LoadConfig(filename string) (*Config, error) {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var config Config
err = yaml.Unmarshal(bytes, &config)
if err != nil {
return nil, err
}
return &config, nil
}