diff options
Diffstat (limited to 'forged/internal/config/config.go')
-rw-r--r-- | forged/internal/config/config.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/forged/internal/config/config.go b/forged/internal/config/config.go new file mode 100644 index 0000000..0166390 --- /dev/null +++ b/forged/internal/config/config.go @@ -0,0 +1,72 @@ +package config + +import ( + "bufio" + "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" +) + +type Config struct { + HTTP struct { + Net string `scfg:"net"` + Addr string `scfg:"addr"` + CookieExpiry int `scfg:"cookie_expiry"` + Root string `scfg:"root"` + ReadTimeout uint32 `scfg:"read_timeout"` + WriteTimeout uint32 `scfg:"write_timeout"` + IdleTimeout uint32 `scfg:"idle_timeout"` + ReverseProxy bool `scfg:"reverse_proxy"` + } `scfg:"http"` + Hooks hooki.Config `scfg:"hooks"` + LMTP struct { + Socket string `scfg:"socket"` + Domain string `scfg:"domain"` + MaxSize int64 `scfg:"max_size"` + WriteTimeout uint32 `scfg:"write_timeout"` + ReadTimeout uint32 `scfg:"read_timeout"` + } `scfg:"lmtp"` + Git struct { + RepoDir string `scfg:"repo_dir"` + Socket string `scfg:"socket"` + DaemonPath string `scfg:"daemon_path"` + } `scfg:"git"` + SSH struct { + Net string `scfg:"net"` + Addr string `scfg:"addr"` + Key string `scfg:"key"` + Root string `scfg:"root"` + } `scfg:"ssh"` + IRC irc.Config `scfg:"irc"` + General struct { + Title string `scfg:"title"` + } `scfg:"general"` + DB database.Config `scfg:"db"` + Pprof struct { + Net string `scfg:"net"` + Addr string `scfg:"addr"` + } `scfg:"pprof"` +} + +func Open(path string) (config Config, err error) { + var configFile *os.File + + if configFile, err = os.Open(path); err != nil { + return config, err + } + defer configFile.Close() + + decoder := scfg.NewDecoder(bufio.NewReader(configFile)) + if err = decoder.Decode(&config); err != nil { + return config, err + } + for _, u := range decoder.UnknownDirectives() { + slog.Warn("unknown configuration directive", "directive", u) + } + + return config, err +} |