aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-01-02 19:30:51 +0000
committerRunxi Yu <me@runxiyu.org>2025-01-02 19:30:51 +0000
commit00f3cb9fb48cfb9768b695bd0d9eb8367ad84782 (patch)
tree2e35b4252b2538c7dbe13d90b501216ded240149 /config.go
parentFile splitting (diff)
downloadmaild-00f3cb9fb48cfb9768b695bd0d9eb8367ad84782.tar.gz
maild-00f3cb9fb48cfb9768b695bd0d9eb8367ad84782.tar.zst
maild-00f3cb9fb48cfb9768b695bd0d9eb8367ad84782.zip
Deliver to inbox
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
+}