summaryrefslogtreecommitdiff
path: root/pkg/config
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-01 18:27:23 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-01 18:27:23 +0200
commit9990266256b8859b3d500ff0fc0fcee6e1e64193 (patch)
tree558148ac5dfa9a49975fe0de2c14a9cfd0725e53 /pkg/config
parent9bd0c60e5007dc30808b7eef17a091fb248d54d6 (diff)
downloadfeed2imap-go-9990266256b8859b3d500ff0fc0fcee6e1e64193.tar.gz
feed2imap-go-9990266256b8859b3d500ff0fc0fcee6e1e64193.tar.bz2
feed2imap-go-9990266256b8859b3d500ff0fc0fcee6e1e64193.zip
Reintroduce yaml-internal `feed`
Diffstat (limited to 'pkg/config')
-rw-r--r--pkg/config/feed.go8
-rw-r--r--pkg/config/yaml.go17
-rw-r--r--pkg/config/yaml_test.go48
3 files changed, 40 insertions, 33 deletions
diff --git a/pkg/config/feed.go b/pkg/config/feed.go
index 9a88fc9..e6788d2 100644
--- a/pkg/config/feed.go
+++ b/pkg/config/feed.go
@@ -2,10 +2,10 @@ package config
// One stored feed
type Feed struct {
- Name string
- Target []string `yaml:"-"`
- Url string
- Options `yaml:"-"` // not parsed directly
+ Name string
+ Target []string
+ Url string
+ Options
}
// Convenience type for all feeds
diff --git a/pkg/config/yaml.go b/pkg/config/yaml.go
index 1afba0a..66f099a 100644
--- a/pkg/config/yaml.go
+++ b/pkg/config/yaml.go
@@ -29,9 +29,14 @@ type group struct {
Feeds []configGroupFeed
}
+type feed struct {
+ Name string
+ Url string
+}
+
type configGroupFeed struct {
Target yaml.Node
- Feed Feed `yaml:",inline"`
+ Feed feed `yaml:",inline"`
Group group `yaml:",inline"`
Options Map `yaml:",inline"`
}
@@ -187,7 +192,6 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds, globalFeedO
return fmt.Errorf("Entry with targetStr %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")
@@ -204,9 +208,12 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds, globalFeedO
}
}
- feedCopy.Options = opt
- feedCopy.Target = target
- feeds[name] = &feedCopy
+ feeds[name] = &Feed{
+ Name: name,
+ Url: f.Feed.Url,
+ Options: opt,
+ Target: target,
+ }
case f.isGroup():
if err := buildFeeds(f.Group.Feeds, target, feeds, globalFeedOptions); err != nil {
diff --git a/pkg/config/yaml_test.go b/pkg/config/yaml_test.go
index ded9453..a3254d5 100644
--- a/pkg/config/yaml_test.go
+++ b/pkg/config/yaml_test.go
@@ -70,51 +70,51 @@ func TestBuildFeeds(tst *testing.T) {
{name: "Empty input", wantErr: false, target: "", feeds: nil, result: Feeds{}},
{name: "Empty Feed", wantErr: true, target: "",
feeds: []configGroupFeed{
- {Target: n("foo"), Feed: Feed{Url: "google.de"}},
+ {Target: n("foo"), Feed: feed{Url: "google.de"}},
}, result: Feeds{}},
{name: "Empty Feed", wantErr: true, target: "",
feeds: []configGroupFeed{
- {Feed: Feed{Url: "google.de"}},
+ {Feed: feed{Url: "google.de"}},
}, result: Feeds{}},
{name: "Duplicate Feed Name", wantErr: true, target: "",
feeds: []configGroupFeed{
- {Feed: Feed{Name: "Dup"}},
- {Feed: Feed{Name: "Dup"}},
+ {Feed: feed{Name: "Dup"}},
+ {Feed: feed{Name: "Dup"}},
}, result: Feeds{}},
{name: "Simple", wantErr: false, target: "",
feeds: []configGroupFeed{
- {Target: n("foo"), Feed: Feed{Name: "muh"}},
+ {Target: n("foo"), Feed: feed{Name: "muh"}},
},
result: Feeds{"muh": &Feed{Name: "muh", Target: t("foo")}},
},
{name: "Simple With Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Target: n("foo"), Feed: Feed{Name: "muh"}},
+ {Target: n("foo"), Feed: feed{Name: "muh"}},
},
result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.foo")}},
},
{name: "Simple Without Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Feed: Feed{Name: "muh"}},
+ {Feed: feed{Name: "muh"}},
},
result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.muh")}},
},
{name: "Simple With Nil Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Target: yaml.Node{Tag: "!!null"}, Feed: Feed{Name: "muh"}},
+ {Target: yaml.Node{Tag: "!!null"}, Feed: feed{Name: "muh"}},
},
result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep")}},
},
{name: "Simple With Empty Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Target: n(""), Feed: Feed{Name: "muh"}},
+ {Target: n(""), Feed: feed{Name: "muh"}},
},
result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep")}},
},
{name: "Multiple Feeds", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Target: n("foo"), Feed: Feed{Name: "muh"}},
- {Feed: Feed{Name: "bar"}},
+ {Target: n("foo"), Feed: feed{Name: "muh"}},
+ {Feed: feed{Name: "bar"}},
},
result: Feeds{
"muh": &Feed{Name: "muh", Target: t("moep.foo")},
@@ -130,9 +130,9 @@ func TestBuildFeeds(tst *testing.T) {
{name: "Simple Group", wantErr: false, target: "",
feeds: []configGroupFeed{
{Group: group{Group: "G1", Feeds: []configGroupFeed{
- {Target: n("bar"), Feed: Feed{Name: "F1"}},
- {Target: n(""), Feed: Feed{Name: "F2"}},
- {Feed: Feed{Name: "F3"}},
+ {Target: n("bar"), Feed: feed{Name: "F1"}},
+ {Target: n(""), Feed: feed{Name: "F2"}},
+ {Feed: feed{Name: "F3"}},
}}},
},
result: Feeds{
@@ -144,13 +144,13 @@ func TestBuildFeeds(tst *testing.T) {
{name: "Nested Groups", wantErr: false, target: "",
feeds: []configGroupFeed{
{Group: group{Group: "G1", Feeds: []configGroupFeed{
- {Feed: Feed{Name: "F0"}},
+ {Feed: feed{Name: "F0"}},
{Target: n("bar"), Group: group{Group: "G2",
- Feeds: []configGroupFeed{{Feed: Feed{Name: "F1"}}}}},
+ Feeds: []configGroupFeed{{Feed: feed{Name: "F1"}}}}},
{Target: n(""), Group: group{Group: "G3",
- Feeds: []configGroupFeed{{Target: n("baz"), Feed: Feed{Name: "F2"}}}}},
+ Feeds: []configGroupFeed{{Target: n("baz"), Feed: feed{Name: "F2"}}}}},
{Group: group{Group: "G4",
- Feeds: []configGroupFeed{{Feed: Feed{Name: "F3"}}}}},
+ Feeds: []configGroupFeed{{Feed: feed{Name: "F3"}}}}},
}}},
},
result: Feeds{
@@ -227,7 +227,7 @@ feeds:
wantErr: false,
config: defaultConfig([]configGroupFeed{{
Target: n("bar"),
- Feed: Feed{
+ Feed: feed{
Name: "Foo",
Url: "whatever",
},
@@ -248,7 +248,7 @@ feeds:
wantErr: false,
config: defaultConfig([]configGroupFeed{
{
- Feed: Feed{
+ Feed: feed{
Name: "Foo",
Url: "whatever",
},
@@ -256,7 +256,7 @@ feeds:
},
{
Target: n("bla"),
- Feed: Feed{
+ Feed: feed{
Name: "Shrubbery",
Url: "google.de",
},
@@ -291,7 +291,7 @@ feeds:
`,
wantErr: false,
config: defaultConfig([]configGroupFeed{
- {Feed: Feed{
+ {Feed: feed{
Name: "Foo",
Url: "whatever",
}},
@@ -301,10 +301,10 @@ feeds:
{Target: n(""), Group: group{
Group: "G2",
Feeds: []configGroupFeed{
- {Feed: Feed{Name: "F1", Url: "google.de"}},
+ {Feed: feed{Name: "F1", Url: "google.de"}},
}},
},
- {Feed: Feed{Name: "F2"}},
+ {Feed: feed{Name: "F2"}},
{Group: group{Group: "G3"}},
}},
},