all repos — mx @ 4ae2f6e2c20f22ebb6b3d478313dce9a89c870e6

work in progress MUA

config/config.go (view raw)

 1package config
 2
 3import (
 4	"fmt"
 5	"os"
 6	"path/filepath"
 7
 8	"gopkg.in/yaml.v2"
 9)
10
11var Config ConfigYaml
12
13func init() {
14	Config = *ParseConfig()
15}
16
17type ConfigYaml struct {
18	Maildir struct {
19		Base    string   `yaml:"base"`
20		Inbox   string   `yaml:"inbox"`
21		Sent    string   `yaml:"sent"`
22		Trash   string   `yaml:"trash"`
23		Junk    string   `yaml:"junk"`
24		Archive string   `yaml:"archive"`
25		Drafts  string   `yaml:"drafts"`
26		Custom  []string `yaml:"custom"`
27	} `yaml:"maildir"`
28}
29
30func ParseConfig() *ConfigYaml {
31	cfg := ConfigYaml{}
32	hd, _ := os.UserHomeDir()
33
34	// ~/.config/mx/mx.yaml
35	configPath := filepath.Join(hd, ".config", "mx", "mx.yaml")
36
37	cfile, err := os.ReadFile(configPath)
38	if err != nil {
39		fmt.Errorf("error: %+v\n", err)
40		return nil
41	}
42	if err = yaml.Unmarshal(cfile, &cfg); err != nil {
43		fmt.Errorf("error: %+v\n", err)
44		return nil
45	}
46	return &cfg
47}