diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-25 17:00:57 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-25 17:00:57 +0200 |
commit | 573ce1982da2e754947453fdaf0d50204873acb4 (patch) | |
tree | f6528235dce77db514ce4442ee8817e993fdcc86 /internal/config/config.go | |
parent | d21881150c09986571a563eaf30bc1687787e63f (diff) | |
download | feed2imap-go-573ce1982da2e754947453fdaf0d50204873acb4.tar.gz feed2imap-go-573ce1982da2e754947453fdaf0d50204873acb4.tar.bz2 feed2imap-go-573ce1982da2e754947453fdaf0d50204873acb4.zip |
Larger restructuring
Diffstat (limited to '')
-rw-r--r-- | internal/config/config.go | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/internal/config/config.go b/internal/config/config.go deleted file mode 100644 index 6c74c2e..0000000 --- a/internal/config/config.go +++ /dev/null @@ -1,94 +0,0 @@ -package config - -import ( - "fmt" - "os" - "os/user" - "runtime" - "runtime/debug" - "strings" -) - -type Map map[string]interface{} - -type GlobalOptions struct { - Timeout int `yaml:"timeout"` - DefaultEmail string `yaml:"default-email"` - Target string `yaml:"target"` - Parts []string `yaml:"parts"` -} - -var DefaultGlobalOptions = GlobalOptions{ - Timeout: 30, - DefaultEmail: username() + "@" + hostname(), - Target: "", - Parts: []string{"text", "html"}, -} - -type Config struct { - GlobalOptions - GlobalConfig Map -} - -type Options struct { - MinFreq int `yaml:"min-frequency"` - InclImages *bool `yaml:"include-images"` -} - -func (c *Config) Validate() error { - if c.Target == "" { - return fmt.Errorf("No target set!") - } - - return nil -} - -func (c *Config) WithPartText() bool { - for _, part := range c.Parts { - if part == "text" { - return true - } - } - - return false -} - -func (c *Config) WithPartHtml() bool { - for _, part := range c.Parts { - if part == "html" { - return true - } - } - - return false -} - -func Version() string { - bi, ok := debug.ReadBuildInfo() - if !ok { - return "(unknown)" - } - return bi.Main.Version -} - -func hostname() (hostname string) { - hostname, err := os.Hostname() - if err != nil { - hostname = "localhost" - } - return -} - -func username() string { - u, err := user.Current() - switch { - case err != nil: - return "user" - case runtime.GOOS == "windows": - // the domain is attached -- remove it again - split := strings.Split(u.Username, "\\") - return split[len(split)-1] - default: - return u.Username - } -} |