Refactoring and documentation

This commit is contained in:
Tulir Asokan
2018-03-23 23:39:17 +02:00
parent 997948ccad
commit 38364646a7
3 changed files with 40 additions and 36 deletions

View File

@ -26,6 +26,7 @@ import (
"maunium.net/go/gomuks/ui/debug"
)
// Config contains the main config of gomuks.
type Config struct {
UserID string `yaml:"mxid"`
HS string `yaml:"homeserver"`
@ -35,6 +36,7 @@ type Config struct {
Session *Session `yaml:"-"`
}
// NewConfig creates a config that loads data from the given directory.
func NewConfig(dir string) *Config {
return &Config{
Dir: dir,
@ -42,6 +44,7 @@ func NewConfig(dir string) *Config {
}
}
// Clear clears the session cache and removes all history.
func (config *Config) Clear() {
if config.Session != nil {
config.Session.Clear()
@ -49,6 +52,7 @@ func (config *Config) Clear() {
os.RemoveAll(config.HistoryDir)
}
// Load loads the config from config.yaml in the directory given to the config struct.
func (config *Config) Load() {
os.MkdirAll(config.Dir, 0700)
os.MkdirAll(config.HistoryDir, 0700)
@ -70,6 +74,7 @@ func (config *Config) Load() {
}
}
// Save saves this config to config.yaml in the directory given to the config struct.
func (config *Config) Save() {
os.MkdirAll(config.Dir, 0700)
data, err := yaml.Marshal(&config)