From f11775b3d292b1b119f7198d7e565749a4b9c847 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 5 Apr 2025 22:18:24 +0800 Subject: Move scfg into the repo and don't error out on unknown fields --- config.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'config.go') diff --git a/config.go b/config.go index 5abbfb0..2158721 100644 --- a/config.go +++ b/config.go @@ -7,10 +7,11 @@ import ( "bufio" "context" "errors" + "log/slog" "os" - "codeberg.org/emersion/go-scfg" "github.com/jackc/pgx/v5/pgxpool" + "go.lindenii.runxiyu.org/forge/internal/scfg" ) type Config struct { @@ -69,10 +70,7 @@ type Config struct { // [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. +// TODO: Error out when there are missing fields func (s *Server) LoadConfig(path string) (err error) { var configFile *os.File if configFile, err = os.Open(path); err != nil { @@ -84,6 +82,9 @@ func (s *Server) LoadConfig(path string) (err error) { if err = decoder.Decode(&s.config); err != nil { return 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") -- cgit v1.2.3