aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-31 16:59:18 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-31 16:59:18 +0800
commit655b6b211ae6df0186abd740f248939f7ddeaec1 (patch)
treeec5cdbbc52222f62c8fbb0bcf2a1aa7a9f6eb8b6 /config.go
parentCorrect table headers in MR indices (diff)
downloadforge-655b6b211ae6df0186abd740f248939f7ddeaec1.tar.gz
forge-655b6b211ae6df0186abd740f248939f7ddeaec1.tar.zst
forge-655b6b211ae6df0186abd740f248939f7ddeaec1.zip
Add descriptive comments to most Go functions
Diffstat (limited to 'config.go')
-rw-r--r--config.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/config.go b/config.go
index 8bf05d9..1973f3d 100644
--- a/config.go
+++ b/config.go
@@ -13,8 +13,9 @@ import (
"go.lindenii.runxiyu.org/lindenii-common/scfg"
)
-var database *pgxpool.Pool
-
+// config holds the global configuration used by this instance. There is
+// currently no synchronization mechanism, so it must not be modified after
+// request handlers are spawned.
var config struct {
HTTP struct {
Net string `scfg:"net"`
@@ -57,16 +58,23 @@ var config struct {
} `scfg:"db"`
}
+// loadConfig loads a configuration file from the specified path and unmarshals
+// it to the global [config] struct. This may race with concurrent reads from
+// [config]; additional synchronization is necessary if the configuration is to
+// be made reloadable.
+//
+// TODO: Currently, it returns an error when the user specifies any unknown
+// configuration patterns, but silently ignores fields in the [config] struct
+// that is not present in the user's configuration file. We would prefer the
+// exact opposite behavior.
func loadConfig(path string) (err error) {
var configFile *os.File
- var decoder *scfg.Decoder
-
if configFile, err = os.Open(path); err != nil {
return err
}
defer configFile.Close()
- decoder = scfg.NewDecoder(bufio.NewReader(configFile))
+ decoder := scfg.NewDecoder(bufio.NewReader(configFile))
if err = decoder.Decode(&config); err != nil {
return err
}