diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-31 16:59:18 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-31 16:59:18 +0800 |
commit | 655b6b211ae6df0186abd740f248939f7ddeaec1 (patch) | |
tree | ec5cdbbc52222f62c8fbb0bcf2a1aa7a9f6eb8b6 /config.go | |
parent | Correct table headers in MR indices (diff) | |
download | forge-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.go | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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 } |