aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/config.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-01 16:42:31 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-01 16:42:31 +0200
commitd7de88398ca67d7213fb849db60e5963fd3bc32f (patch)
tree9168196dc5053185eefc951c3c0be0e8024b2a1d /pkg/config/config.go
parent042361bc0cf7c0c4a0c14ee554e0e32c6088dee8 (diff)
downloadfeed2imap-go-d7de88398ca67d7213fb849db60e5963fd3bc32f.tar.gz
feed2imap-go-d7de88398ca67d7213fb849db60e5963fd3bc32f.tar.bz2
feed2imap-go-d7de88398ca67d7213fb849db60e5963fd3bc32f.zip
Remove pointers from feed options. Detect unknown fields in feed and group options.
Diffstat (limited to '')
-rw-r--r--pkg/config/config.go64
1 files changed, 14 insertions, 50 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 885b80e..de8e4ad 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -34,56 +34,29 @@ var DefaultGlobalOptions = GlobalOptions{
}
// Per feed options
+// NB: Always specify a yaml name, as it is later used in processing
type Options struct {
- MinFreq *int `yaml:"min-frequency"`
- InclImages *bool `yaml:"include-images"`
- Disable *bool `yaml:"disable"`
- IgnHash *bool `yaml:"ignore-hash"`
- AlwaysNew *bool `yaml:"always-new"`
- NoTLS *bool `yaml:"tls-no-verify"`
-}
-
-func (opt *Options) mergeFrom(other Options) {
- if opt.MinFreq == nil {
- opt.MinFreq = other.MinFreq
- }
- if opt.InclImages == nil {
- opt.InclImages = other.InclImages
- }
- if opt.IgnHash == nil {
- opt.IgnHash = other.IgnHash
- }
- if opt.AlwaysNew == nil {
- opt.AlwaysNew = other.AlwaysNew
- }
- if opt.Disable == nil {
- opt.Disable = other.Disable
- }
- if opt.NoTLS == nil {
- opt.NoTLS = other.NoTLS
- }
+ MinFreq int `yaml:"min-frequency"`
+ InclImages bool `yaml:"include-images"`
+ Disable bool `yaml:"disable"`
+ IgnHash bool `yaml:"ignore-hash"`
+ AlwaysNew bool `yaml:"always-new"`
+ NoTLS bool `yaml:"tls-no-verify"`
}
// Default feed options
-var DefaultFeedOptions Options
-
-func init() {
- one := 1
- fal := false
- DefaultFeedOptions = Options{
- MinFreq: &one,
- InclImages: &fal,
- IgnHash: &fal,
- AlwaysNew: &fal,
- Disable: &fal,
- NoTLS: &fal,
- }
+var DefaultFeedOptions = Options{
+ MinFreq: 1,
+ InclImages: false,
+ IgnHash: false,
+ AlwaysNew: false,
+ Disable: false,
+ NoTLS: false,
}
// Config holds the global configuration options and the configured feeds
type Config struct {
GlobalOptions `yaml:",inline"`
- GlobalConfig Map `yaml:",inline"`
FeedOptions Options `yaml:"options"`
Feeds Feeds `yaml:"-"`
}
@@ -93,7 +66,6 @@ func WithDefault() *Config {
return &Config{
GlobalOptions: DefaultGlobalOptions,
FeedOptions: DefaultFeedOptions,
- GlobalConfig: Map{},
Feeds: Feeds{},
}
}
@@ -140,17 +112,9 @@ 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 {