diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-10-17 17:14:14 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-10-18 18:36:04 +0200 |
commit | 2d5e4aa85ae103cdb3059652fda47c87d586484c (patch) | |
tree | de66fa60a70dda44b078563b973a08cc36d13baa /pkg/config | |
parent | 5c29e49f9f422c8889ce2ed6b5b5a2914b55cace (diff) | |
download | feed2imap-go-2d5e4aa85ae103cdb3059652fda47c87d586484c.tar.gz feed2imap-go-2d5e4aa85ae103cdb3059652fda47c87d586484c.tar.bz2 feed2imap-go-2d5e4aa85ae103cdb3059652fda47c87d586484c.zip |
Restructuring
Diffstat (limited to 'pkg/config')
-rw-r--r-- | pkg/config/yaml.go | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/pkg/config/yaml.go b/pkg/config/yaml.go index 57991eb..4716ce5 100644 --- a/pkg/config/yaml.go +++ b/pkg/config/yaml.go @@ -183,38 +183,19 @@ func buildOptions(globalFeedOptions *Options, options Map) (feedOptions Options, // Fetch the group structure and populate the `targetStr` fields in the feeds func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds, - globalFeedOptions *Options, autoTarget bool, globalTarget *Url) error { + globalFeedOptions *Options, autoTarget bool, globalTarget *Url) (err error) { for _, f := range cfg { var fTarget []string rawTarget := f.target(autoTarget) if isRecognizedUrl(rawTarget) { - // this whole block is solely for compatibility with old feed2imap - // there it was common to specify the whole URL for each feed - if isMaildirUrl(rawTarget) { - // old feed2imap supported maildir, we don't - return fmt.Errorf("Line %d: Maildir is not supported.", f.Target.Line) - } - - url := Url{} - if err := url.UnmarshalYAML(&f.Target); err != nil { + // deprecated old-style URLs as target + if fTarget, err = handleUrlTarget(rawTarget, &f.Target, globalTarget); err != nil { return err } - - if globalTarget.Empty() { - // assign first feed as global url - *globalTarget = url.BaseUrl() - } else if !globalTarget.CommonBaseUrl(url) { - // if we have a url, it must be the same prefix as the global url - return fmt.Errorf("Line %d: Given URL endpoint '%s' does not match previous endpoint '%s'.", - f.Target.Line, - url.BaseUrl(), - globalTarget.BaseUrl()) - } - - fTarget = url.RootPath() // we are given the absolute path, so now appending trickery } else { + // new-style tree-like structure fTarget = appTarget(target, rawTarget) } @@ -254,7 +235,7 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds, log.Warnf("Unknown option '%s' for group '%s'. Ignored!", optName, f.Group.Group) } - if err := buildFeeds(f.Group.Feeds, fTarget, feeds, &opt, autoTarget, globalTarget); err != nil { + if err = buildFeeds(f.Group.Feeds, fTarget, feeds, &opt, autoTarget, globalTarget); err != nil { return err } } @@ -262,3 +243,31 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds, return nil } + +func handleUrlTarget(targetStr string, targetNode *yaml.Node, globalTarget *Url) ([]string, error) { + // this whole function is solely for compatibility with old feed2imap + // there it was common to specify the whole URL for each feed + if isMaildirUrl(targetStr) { + // old feed2imap supported maildir, we don't + return nil, fmt.Errorf("Line %d: Maildir is not supported.", targetNode.Line) + } + + url := Url{} + if err := url.UnmarshalYAML(targetNode); err != nil { + return nil, err + } + + if globalTarget.Empty() { + // assign first feed as global url + *globalTarget = url.BaseUrl() + } else if !globalTarget.CommonBaseUrl(url) { + // if we have a url, it must be the same prefix as the global url + return nil, fmt.Errorf("Line %d: Given URL endpoint '%s' does not match previous endpoint '%s'.", + targetNode.Line, + url.BaseUrl(), + globalTarget.BaseUrl()) + } + + return url.RootPath(), // we are given the absolute path, so now appending trickery + nil +} |