From b279bf1f8817451529fea30d2fce9a97a71ce579 Mon Sep 17 00:00:00 2001 From: Daniel Barton Date: Sat, 13 Apr 2024 23:28:07 +0800 Subject: [PATCH] Reorder config loading to load config and *then* fill in missing defaults --- config/config.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 3770115..1b7dbe8 100644 --- a/config/config.go +++ b/config/config.go @@ -332,12 +332,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 @@ -513,6 +507,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