diff options
| author | Paul Buetow <paul@buetow.org> | 2023-06-29 09:28:35 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-06-29 09:28:35 +0300 |
| commit | 16602d176cb82da0f9980b95ac0ef6eec47953a2 (patch) | |
| tree | 26ba82dc33a61b6de77e866d29cd719c31668ac1 /internal/config/config.go | |
| parent | 84e5a4ae93eed6397a6cbf6091a0f5b3eacc78e2 (diff) | |
refactor config initialization
Diffstat (limited to 'internal/config/config.go')
| -rw-r--r-- | internal/config/config.go | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index ec4ea67..2f8c62b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -21,19 +21,7 @@ type Config struct { nodeNumberCache map[string]int } -func New(arg any) (Config, error) { - switch arg := arg.(type) { - case string: - return newFromConfigFile(arg) - case Config: - // Used to initialize a custom config from unit tests. - return arg.initialize() - default: - panic("unable to initialize config") - } -} - -func newFromConfigFile(configFile string) (Config, error) { +func New(configFile string) (Config, error) { var conf Config file, err := os.Open(configFile) @@ -52,6 +40,10 @@ func newFromConfigFile(configFile string) (Config, error) { return conf, err } + return NewFromConfig(conf) +} + +func NewFromConfig(conf Config) (Config, error) { return conf.initialize() } |
