From 00f3cb9fb48cfb9768b695bd0d9eb8367ad84782 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 2 Jan 2025 19:30:51 +0000 Subject: Deliver to inbox --- config.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'config.go') 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 +} -- cgit v1.2.3