summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/config/config.go17
-rw-r--r--pkg/config/feed.go2
-rw-r--r--pkg/config/yaml.go5
-rw-r--r--pkg/config/yaml_test.go26
4 files changed, 34 insertions, 16 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 83c952f..1b95f61 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -39,6 +39,15 @@ type Options struct {
InclImages *bool `yaml:"include-images"`
}
+func (opt *Options) mergeFrom(other Options) {
+ if opt.MinFreq == nil {
+ opt.MinFreq = other.MinFreq
+ }
+ if opt.InclImages == nil {
+ opt.InclImages = other.InclImages
+ }
+}
+
// Default feed options
var DefaultFeedOptions Options
@@ -111,9 +120,17 @@ func Load(path string) (*Config, error) {
return nil, fmt.Errorf("while parsing: %w", err)
}
+ cfg.pushFeedOptions()
+
return cfg, nil
}
+func (cfg *Config) pushFeedOptions() {
+ for _, feed := range cfg.Feeds {
+ feed.Options.mergeFrom(cfg.FeedOptions)
+ }
+}
+
func hostname() (hostname string) {
hostname, err := os.Hostname()
if err != nil {
diff --git a/pkg/config/feed.go b/pkg/config/feed.go
index 4641cbc..a861e2e 100644
--- a/pkg/config/feed.go
+++ b/pkg/config/feed.go
@@ -9,4 +9,4 @@ type Feed struct {
}
// Convenience type for all feeds
-type Feeds map[string]Feed
+type Feeds map[string]*Feed
diff --git a/pkg/config/yaml.go b/pkg/config/yaml.go
index 53d4d98..84f4af6 100644
--- a/pkg/config/yaml.go
+++ b/pkg/config/yaml.go
@@ -98,6 +98,7 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds) error {
return fmt.Errorf("Entry with Target %s is both a Feed and a group", target)
case f.isFeed():
+ feedCopy := f.Feed
name := f.Feed.Name
if name == "" {
return fmt.Errorf("Unnamed feed")
@@ -106,8 +107,8 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds) error {
if _, ok := feeds[name]; ok {
return fmt.Errorf("Duplicate Feed Name '%s'", name)
}
- f.Feed.Target = target
- feeds[name] = f.Feed
+ feedCopy.Target = target
+ feeds[name] = &feedCopy
case f.isGroup():
if err := buildFeeds(f.Group.Feeds, target, feeds); err != nil {
diff --git a/pkg/config/yaml_test.go b/pkg/config/yaml_test.go
index 501ead3..40ee325 100644
--- a/pkg/config/yaml_test.go
+++ b/pkg/config/yaml_test.go
@@ -44,25 +44,25 @@ func TestBuildFeeds(tst *testing.T) {
feeds: []configGroupFeed{
{Target: s("foo"), Feed: Feed{Name: "muh"}},
},
- result: Feeds{"muh": Feed{Name: "muh", Target: t("foo")}},
+ result: Feeds{"muh": &Feed{Name: "muh", Target: t("foo")}},
},
{name: "Simple With Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
{Target: s("foo"), Feed: Feed{Name: "muh"}},
},
- result: Feeds{"muh": Feed{Name: "muh", Target: t("moep.foo")}},
+ result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.foo")}},
},
{name: "Simple With Nil Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
{Target: nil, Feed: Feed{Name: "muh"}},
},
- result: Feeds{"muh": Feed{Name: "muh", Target: t("moep.muh")}},
+ result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.muh")}},
},
{name: "Simple With Empty Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
{Target: s(""), Feed: Feed{Name: "muh"}},
},
- result: Feeds{"muh": Feed{Name: "muh", Target: t("moep")}},
+ result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep")}},
},
{name: "Multiple Feeds", wantErr: false, target: "moep",
feeds: []configGroupFeed{
@@ -70,8 +70,8 @@ func TestBuildFeeds(tst *testing.T) {
{Target: nil, Feed: Feed{Name: "bar"}},
},
result: Feeds{
- "muh": Feed{Name: "muh", Target: t("moep.foo")},
- "bar": Feed{Name: "bar", Target: t("moep.bar")},
+ "muh": &Feed{Name: "muh", Target: t("moep.foo")},
+ "bar": &Feed{Name: "bar", Target: t("moep.bar")},
},
},
{name: "Empty Group", wantErr: false, target: "",
@@ -89,9 +89,9 @@ func TestBuildFeeds(tst *testing.T) {
}}},
},
result: Feeds{
- "F1": Feed{Name: "F1", Target: t("G1.bar")},
- "F2": Feed{Name: "F2", Target: t("G1")},
- "F3": Feed{Name: "F3", Target: t("G1.F3")},
+ "F1": &Feed{Name: "F1", Target: t("G1.bar")},
+ "F2": &Feed{Name: "F2", Target: t("G1")},
+ "F3": &Feed{Name: "F3", Target: t("G1.F3")},
},
},
{name: "Nested Groups", wantErr: false, target: "",
@@ -107,10 +107,10 @@ func TestBuildFeeds(tst *testing.T) {
}}},
},
result: Feeds{
- "F0": Feed{Name: "F0", Target: t("G1.F0")},
- "F1": Feed{Name: "F1", Target: t("G1.bar.F1")},
- "F2": Feed{Name: "F2", Target: t("G1.baz")},
- "F3": Feed{Name: "F3", Target: t("G1.G4.F3")},
+ "F0": &Feed{Name: "F0", Target: t("G1.F0")},
+ "F1": &Feed{Name: "F1", Target: t("G1.bar.F1")},
+ "F2": &Feed{Name: "F2", Target: t("G1.baz")},
+ "F3": &Feed{Name: "F3", Target: t("G1.G4.F3")},
},
},
}