From 161dd4405474cc905e6912bab243509a3a6f88db Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Mon, 20 Apr 2020 01:01:13 +0200 Subject: GlobalOptions --- internal/config/config.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'internal/config') 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 + } +} -- cgit v1.2.3-70-g09d2