diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-03-13 21:58:43 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-03-13 21:58:43 +0200 |
commit | 90629c5c78916ba9be982afb9b8435ea58be166b (patch) | |
tree | 3c1720f695e43e4de8a0f68f0d3c9da65ffd82d1 /config.go | |
parent | f0333df1b2b6e0ef54a580668cb759a094b56010 (diff) |
Code additions/edits
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -29,14 +29,23 @@ type Config struct { MXID string `yaml:"mxid"` HS string `yaml:"homeserver"` - dir string `yaml:"-"` - Session *Session `yaml:"-"` + dir string `yaml:"-"` + gmx Gomuks `yaml:"-"` + debug DebugPrinter `yaml:"-"` + Session *Session `yaml:"-"` } -func (config *Config) Load(dir string) { - config.dir = dir - os.MkdirAll(dir, 0700) - configPath := filepath.Join(dir, "config.yaml") +func NewConfig(gmx Gomuks, dir string) *Config { + return &Config{ + gmx: gmx, + debug: gmx.Debug(), + dir: dir, + } +} + +func (config *Config) Load() { + os.MkdirAll(config.dir, 0700) + configPath := filepath.Join(config.dir, "config.yaml") data, err := ioutil.ReadFile(configPath) if err != nil { if os.IsNotExist(err) { @@ -55,16 +64,17 @@ func (config *Config) Load(dir string) { } func (config *Config) Save() { + os.MkdirAll(config.dir, 0700) data, err := yaml.Marshal(&config) if err != nil { - debug.Print("Failed to marshal config") + config.debug.Print("Failed to marshal config") panic(err) } path := filepath.Join(config.dir, "config.yaml") err = ioutil.WriteFile(path, data, 0600) if err != nil { - debug.Print("Failed to write config to", path) + config.debug.Print("Failed to write config to", path) panic(err) } } |