diff options
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -1,7 +1,34 @@ package main +import ( + "bufio" + "go.lindenii.runxiyu.org/lindenii-common/scfg" + "os" + "sync" +) + var config struct { Server_name string `scfg:"server_name"` + Inbox_path string `scfg:"inbox_path"` } +var config_mutex sync.RWMutex -// TODO: edit scfg to require fields to exist unless explicitly marked optional. +func load_config(path string) error { + config_file, err := os.Open(path) + if err != nil { + return err + } + decoder := scfg.NewDecoder(bufio.NewReader(config_file)) + if func() error { + config_mutex.Lock() + defer config_mutex.Unlock() + err = decoder.Decode(&config) + if err != nil { + return err + } + return nil + }() != nil { + return err + } + return nil +} |