aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/config/config.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--forged/internal/config/config.go (renamed from forged/internal/unsorted/config.go)44
1 files changed, 11 insertions, 33 deletions
diff --git a/forged/internal/unsorted/config.go b/forged/internal/config/config.go
index 9f07480..0166390 100644
--- a/forged/internal/unsorted/config.go
+++ b/forged/internal/config/config.go
@@ -1,15 +1,12 @@
-// SPDX-License-Identifier: AGPL-3.0-only
-// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
-
-package unsorted
+package config
import (
"bufio"
- "errors"
"log/slog"
"os"
"go.lindenii.runxiyu.org/forge/forged/internal/database"
+ "go.lindenii.runxiyu.org/forge/forged/internal/hooki"
"go.lindenii.runxiyu.org/forge/forged/internal/irc"
"go.lindenii.runxiyu.org/forge/forged/internal/scfg"
)
@@ -25,11 +22,8 @@ type Config struct {
IdleTimeout uint32 `scfg:"idle_timeout"`
ReverseProxy bool `scfg:"reverse_proxy"`
} `scfg:"http"`
- Hooks struct {
- Socket string `scfg:"socket"`
- Execs string `scfg:"execs"`
- } `scfg:"hooks"`
- LMTP struct {
+ Hooks hooki.Config `scfg:"hooks"`
+ LMTP struct {
Socket string `scfg:"socket"`
Domain string `scfg:"domain"`
MaxSize int64 `scfg:"max_size"`
@@ -51,44 +45,28 @@ type Config struct {
General struct {
Title string `scfg:"title"`
} `scfg:"general"`
- DB struct {
- Type string `scfg:"type"`
- Conn string `scfg:"conn"`
- } `scfg:"db"`
+ DB database.Config `scfg:"db"`
Pprof struct {
Net string `scfg:"net"`
Addr string `scfg:"addr"`
} `scfg:"pprof"`
}
-// 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.
-func (s *Server) loadConfig(path string) (err error) {
+func Open(path string) (config Config, err error) {
var configFile *os.File
+
if configFile, err = os.Open(path); err != nil {
- return err
+ return config, err
}
defer configFile.Close()
decoder := scfg.NewDecoder(bufio.NewReader(configFile))
- if err = decoder.Decode(&s.config); err != nil {
- return err
+ if err = decoder.Decode(&config); err != nil {
+ return config, err
}
for _, u := range decoder.UnknownDirectives() {
slog.Warn("unknown configuration directive", "directive", u)
}
- if s.config.DB.Type != "postgres" {
- return errors.New("unsupported database type")
- }
-
- if s.database, err = database.Open(s.config.DB.Conn); err != nil {
- return err
- }
-
- s.globalData["forge_title"] = s.config.General.Title
-
- return nil
+ return config, err
}