diff options
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 + } +} |