aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/config.go b/config.go
index 1a89987..c4b5579 100644
--- a/config.go
+++ b/config.go
@@ -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
+}