package config import ( "fmt" "os" "path/filepath" "gopkg.in/yaml.v2" ) var Config ConfigYaml func init() { Config = *ParseConfig() } type ConfigYaml struct { Maildir struct { Base string `yaml:"base"` Inbox string `yaml:"inbox"` Sent string `yaml:"sent"` Trash string `yaml:"trash"` Junk string `yaml:"junk"` Archive string `yaml:"archive"` Drafts string `yaml:"drafts"` Custom []string `yaml:"custom"` } `yaml:"maildir"` } func ParseConfig() *ConfigYaml { cfg := ConfigYaml{} hd, _ := os.UserHomeDir() // ~/.config/mx/mx.yaml configPath := filepath.Join(hd, ".config", "mx", "mx.yaml") cfile, err := os.ReadFile(configPath) if err != nil { fmt.Errorf("error: %+v\n", err) return nil } if err = yaml.Unmarshal(cfile, &cfg); err != nil { fmt.Errorf("error: %+v\n", err) return nil } return &cfg }