/
config.go
49 lines (40 loc) · 1.1 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
package util
import (
"os"
"gopkg.in/yaml.v2"
)
// Config has all the config (aside from credentials) for what to do.
type Config struct {
Albums []*ConfigAlbum `yaml:"albums"`
Every string `yaml:"every,omitempty"`
Prometheus ConfigPrometheus `yaml:"prometheus,omitempty"`
Pprof ConfigPprof `yaml:"pprof,omitempty"`
}
type ConfigAlbum struct {
Name string `yaml:"name"`
DryRun *bool `yaml:"dryRun,omitempty"`
Delete *bool `yaml:"delete,omitempty"`
ForcePublish *bool `yaml:"forcePublish,omitempty"`
Sources ConfigAlbumSources `yaml:"sources"`
}
type ConfigAlbumSources struct {
Googlephotos []string `json:"googlephotos,omitempty"`
}
type ConfigPrometheus struct {
Listen string `yaml:"listen"`
}
type ConfigPprof struct {
Listen string `yaml:"listen"`
}
func LoadConfig(filename string) (*Config, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
c := Config{}
if err = yaml.NewDecoder(f).Decode(&c); err != nil {
return nil, err
}
return &c, nil
}