diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-05 20:21:32 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-05 20:21:32 +0800 |
commit | 71ab9b7f14118f02dd18cd733bd4e0ad19ece590 (patch) | |
tree | 0303cbee651a4e1cee62a348d25066b9543f4425 /config.go | |
parent | git2d: Remove UTF-8 checks (diff) | |
download | forge-71ab9b7f14118f02dd18cd733bd4e0ad19ece590.tar.gz forge-71ab9b7f14118f02dd18cd733bd4e0ad19ece590.tar.zst forge-71ab9b7f14118f02dd18cd733bd4e0ad19ece590.zip |
config shall no longer be a global variable
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -16,7 +16,7 @@ import ( // 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 { +type Config struct { HTTP struct { Net string `scfg:"net"` Addr string `scfg:"addr"` @@ -76,7 +76,7 @@ var config struct { // 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) { +func (s *server) loadConfig(path string) (err error) { var configFile *os.File if configFile, err = os.Open(path); err != nil { return err @@ -84,19 +84,19 @@ func loadConfig(path string) (err error) { defer configFile.Close() decoder := scfg.NewDecoder(bufio.NewReader(configFile)) - if err = decoder.Decode(&config); err != nil { + if err = decoder.Decode(&s.config); err != nil { return err } - if config.DB.Type != "postgres" { + if s.config.DB.Type != "postgres" { return errors.New("unsupported database type") } - if database, err = pgxpool.New(context.Background(), config.DB.Conn); err != nil { + if database, err = pgxpool.New(context.Background(), s.config.DB.Conn); err != nil { return err } - globalData["forge_title"] = config.General.Title + globalData["forge_title"] = s.config.General.Title return nil } |