aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2021-02-21 14:18:14 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2021-02-21 14:18:14 +0100
commit75278be9b54e96d69668214de968a4517f4ab6e6 (patch)
tree245d24219defcfab217bfbddc2c7fc79f2a3a9a2 /internal
parentce42a79ef59d2cad6a3d1cee628d86b4a76517ae (diff)
downloadfeed2imap-go-75278be9b54e96d69668214de968a4517f4ab6e6.tar.gz
feed2imap-go-75278be9b54e96d69668214de968a4517f4ab6e6.tar.bz2
feed2imap-go-75278be9b54e96d69668214de968a4517f4ab6e6.zip
Slight restructuring
Diffstat (limited to 'internal')
-rw-r--r--internal/feed/feed.go12
-rw-r--r--internal/feed/state.go13
2 files changed, 16 insertions, 9 deletions
diff --git a/internal/feed/feed.go b/internal/feed/feed.go
index 4e84443..de28ef8 100644
--- a/internal/feed/feed.go
+++ b/internal/feed/feed.go
@@ -1,6 +1,7 @@
package feed
import (
+ "fmt"
"strings"
"time"
@@ -58,3 +59,14 @@ func (feed *Feed) MarkSuccess() {
feed.cached.Commit()
}
}
+
+func Create(parsedFeed *config.Feed, global config.GlobalOptions) (*Feed, error) {
+ var itemFilter *filter.Filter
+ var err error
+ if parsedFeed.ItemFilter != "" {
+ if itemFilter, err = filter.New(parsedFeed.ItemFilter); err != nil {
+ return nil, fmt.Errorf("Feed %s: Parsing item-filter: %w", parsedFeed.Name, err)
+ }
+ }
+ return &Feed{Feed: parsedFeed, Global: global, filter: itemFilter}, nil
+}
diff --git a/internal/feed/state.go b/internal/feed/state.go
index 41d8751..364616f 100644
--- a/internal/feed/state.go
+++ b/internal/feed/state.go
@@ -2,12 +2,10 @@ package feed
import (
"encoding/json"
- "fmt"
"sync"
"github.com/mmcdole/gofeed"
- "github.com/Necoro/feed2imap-go/internal/feed/filter"
"github.com/Necoro/feed2imap-go/pkg/config"
"github.com/Necoro/feed2imap-go/pkg/log"
)
@@ -163,14 +161,11 @@ func NewState(cfg *config.Config) (*State, error) {
}
for name, parsedFeed := range cfg.Feeds {
- var itemFilter *filter.Filter
- var err error
- if parsedFeed.ItemFilter != "" {
- if itemFilter, err = filter.New(parsedFeed.ItemFilter); err != nil {
- return nil, fmt.Errorf("Feed %s: Parsing item-filter: %w", parsedFeed.Name, err)
- }
+ feed, err := Create(parsedFeed, cfg.GlobalOptions)
+ if err != nil {
+ return nil, err
}
- state.feeds[name] = &Feed{Feed: parsedFeed, Global: cfg.GlobalOptions, filter: itemFilter}
+ state.feeds[name] = feed
}
return &state, nil
/+4 Bumps [github.com/antonmedv/expr](https://github.com/antonmedv/expr) from 1.14.0 to 1.15.1. - [Release notes](https://github.com/antonmedv/expr/releases) - [Commits](https://github.com/antonmedv/expr/compare/v1.14.0...v1.15.1) --- updated-dependencies: - dependency-name: github.com/antonmedv/expr dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> 2023-09-15Bump actions/checkout from 3 to 4dependabot[bot]2-2/+2 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> 2023-08-26Bump golang.org/x/net from 0.12.0 to 0.14.0dependabot[bot]2-6/+6 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.12.0 to 0.14.0. - [Commits](https://github.com/golang/net/compare/v0.12.0...v0.14.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> 2023-08-26Bump github.com/antonmedv/expr from 1.12.6 to 1.14.0dependabot[bot]2-3/+3 Bumps [github.com/antonmedv/expr](https://github.com/antonmedv/expr) from 1.12.6 to 1.14.0. - [Release notes](https://github.com/antonmedv/expr/releases) - [Commits](https://github.com/antonmedv/expr/compare/v1.12.6...v1.14.0) --- updated-dependencies: - dependency-name: github.com/antonmedv/expr dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> 2023-07-15Upgrade depsRené 'Necoro' Neumann2-15/+12 2023-06-13Version Changelog entryv1.7.0René 'Necoro' Neumann1-1/+4 2023-06-13Prepare v1.7.0René 'Necoro' Neumann2-2/+2 2023-06-05Improve changelogRené 'Necoro' Neumann1-2/+4 2023-06-05IMAP client does not need to know about max number of connectionsRené 'Necoro' Neumann2-19/+12 2023-06-04ChangelogRené 'Necoro' Neumann1-0/+4 2023-06-04Add new config option to set max number of IMAP connections.René 'Necoro' Neumann5-20/+26 Default is 5 (as was the hard-coded value before). Closes issue #98. 2023-06-04Improve locking around IMAP connect/disconnect.René 'Necoro' Neumann1-10/+26 This ensures that no connect happens _after_ a disconnect has been issued. Closes issue #97. 2023-05-20Bump golang.org/x/net from 0.9.0 to 0.10.0dependabot[bot]2-2/+3 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.9.0 to 0.10.0. - [Commits](https://github.com/golang/net/compare/v0.9.0...v0.10.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> 2023-05-12Amend changelogRené 'Necoro' Neumann1-0/+1 2023-05-12Issue #95 Add warning when config can be read globally.René 'Necoro' Neumann1-0/+11 2023-05-11Issue #95: Change cache ownership.René 'Necoro' Neumann1-0/+4 There is no need for the cache to be accessible by anyone who is not us. Thus enforce the cache to be stored with 0600. 2023-05-11Issue #95: Add hint about sensible access rights.René 'Necoro' Neumann1-0/+1 2023-04-23[workflow] Port changes also to releaseRené 'Necoro' Neumann1-6/+5 2023-04-23[workflow] Checkout before go setupRené 'Necoro' Neumann1-3/+3 2023-04-23[workflow] determine go version from go.modRené 'Necoro' Neumann1-3/+2 2023-04-23Improve test to also validate error messageRené 'Necoro' Neumann1-42/+39 2023-04-22Fix/improve testsRené 'Necoro' Neumann1-59/+104 2023-04-22Improve error handlingRené 'Necoro' Neumann1-1/+11 2023-04-21Fix workflow: '1.20' needs to be quotedRené 'Necoro' Neumann2-2/+2