From 708cdd0ba8a1db4014898b67a3e6b380b9d94ea6 Mon Sep 17 00:00:00 2001 From: Daniel Barton Date: Thu, 29 Aug 2024 09:48:57 +0800 Subject: [PATCH] chore: reorder config loading to load config, *then* fill in missing defaults (#185) --- config/config.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 395b7ec0..ab7ad370 100644 --- a/config/config.go +++ b/config/config.go @@ -351,12 +351,6 @@ type Configuration struct { // This function does not modify the currently stored global configuration. func NewAtPath(path string) (*Configuration, error) { var c Configuration - // Configures the default values for many of the configuration options present - // in the structs. Values set in the configuration file take priority over the - // default values. - if err := defaults.Set(&c); err != nil { - return nil, err - } // Track the location where we created this configuration. c.path = path return &c, nil @@ -563,6 +557,13 @@ func FromFile(path string) error { return err } + // Configures the default values for many of the configuration options present + // in the structs. Values set in the configuration file will not be overridden by the + // default values. + if err := defaults.Set(c); err != nil { + return err + } + // Store this configuration in the global state. Set(c) return nil