diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-20 01:01:13 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-20 01:01:13 +0200 |
commit | 161dd4405474cc905e6912bab243509a3a6f88db (patch) | |
tree | 6648d425f4ab64325cb6419e619a88d9af61e5ec /internal/config | |
parent | 431a8ddb0c18b0781cba1d01eda3645b361f1b94 (diff) | |
download | feed2imap-go-161dd4405474cc905e6912bab243509a3a6f88db.tar.gz feed2imap-go-161dd4405474cc905e6912bab243509a3a6f88db.tar.bz2 feed2imap-go-161dd4405474cc905e6912bab243509a3a6f88db.zip |
GlobalOptions
Diffstat (limited to 'internal/config')
-rw-r--r-- | internal/config/config.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 0cebf34..6497ce1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,8 +1,28 @@ package config +import ( + "os" + "os/user" + "runtime" + "strings" +) + type Map map[string]interface{} +type GlobalOptions struct { + Timeout int `yaml:"timeout"` + DefaultEmail string `yaml:"default-email"` + Target string `yaml:"target"` +} + +var DefaultGlobalOptions = GlobalOptions{ + Timeout: 30, + DefaultEmail: username() + "@" + hostname(), + Target: "", +} + type Config struct { + GlobalOptions GlobalConfig Map } @@ -10,3 +30,25 @@ type Options struct { MinFreq int `yaml:"min-frequency"` InclImages *bool `yaml:"include-images"` } + +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 + } +} |