diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-17 21:53:15 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-17 21:53:15 +0200 |
commit | b01a98682ad7881c997fe5fc0770ef984013111f (patch) | |
tree | 9b52a17c17390d2738ec862de3799e8ccd9348c7 /internal/config/config.go | |
parent | c96ca310a019a892a717373677ded36dc0b9e2b3 (diff) | |
download | feed2imap-go-b01a98682ad7881c997fe5fc0770ef984013111f.tar.gz feed2imap-go-b01a98682ad7881c997fe5fc0770ef984013111f.tar.bz2 feed2imap-go-b01a98682ad7881c997fe5fc0770ef984013111f.zip |
Split up main.go
Diffstat (limited to 'internal/config/config.go')
-rw-r--r-- | internal/config/config.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..2df7d98 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,52 @@ +package config + +import ( + "fmt" + "gopkg.in/yaml.v3" + "io/ioutil" +) + +type Map map[string]interface{} +type Feeds map[string]*Feed + +type config struct { + GlobalConfig Map `yaml:",inline"` + Feeds []configGroupFeed +} + +type Config struct { + GlobalConfig Map `yaml:",inline"` + Feeds Feeds +} + +type Feed struct { + Name string + Target string + Url string + MinFreq int + Config Map +} + +func Load(path string) (*Config, error) { + buf, err := ioutil.ReadFile(path) + if err != nil { + return nil, fmt.Errorf("while reading '%s': %w", path, err) + } + + var parsedCfg config + if err := yaml.Unmarshal(buf, &parsedCfg); err != nil { + return nil, fmt.Errorf("while unmarshalling: %w", err) + } + fmt.Printf("--- parsedCfg:\n%+v\n\n", parsedCfg) + + var finishedCfg = Config{ + GlobalConfig: parsedCfg.GlobalConfig, + Feeds: make(Feeds), + } + + if err := buildFeeds(parsedCfg.Feeds, "", finishedCfg.Feeds); err != nil { + return nil, fmt.Errorf("while parsing: %w", err) + } + + return &finishedCfg, nil +} |