aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: 9f20203dab756afa9bc293f65e19bac22ce2f7b8 (plain)
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
package main

import (
	"flag"
	"fmt"
	"io/ioutil"
	"log"

	"gopkg.in/yaml.v2"
)

var cfg = flag.String("f", "config.yml", "configuration file")

type ConfigMap map[string]interface{}

type Feed struct {
	Name      string
	Url       string
	MinFreq   int `yaml:"min-frequency"`
	ConfigMap `yaml:",inline"`
}

type Group struct {
	Group string
	Feeds []GroupFeed
}

type GroupFeed struct {
	Target string
	Feed   `yaml:",inline"`
	Group  `yaml:",inline"`
}

type Yaml struct {
	GlobalConfig ConfigMap `yaml:",inline"`
	Feeds        []GroupFeed
}

func main() {
	log.Print("Starting up...")
	flag.Parse()

	log.Printf("Reading configuration file '%s'", *cfg)
	buf, err := ioutil.ReadFile(*cfg)
	if err != nil {
		msg := fmt.Sprint("No file found: ", *cfg)
		panic(msg)
	}

	var m Yaml
	yaml.Unmarshal(buf, &m)
	fmt.Printf("--- m:\n%+v\n\n", m)

}