config: override base_url in development
Alan Pearce alan@alanpearce.eu
Wed, 17 Apr 2024 19:53:22 +0200
1 files changed, 15 insertions(+), 0 deletions(-)
jump to
M internal/config/config.go → internal/config/config.go
@@ -44,6 +44,15 @@ } Menus map[string][]MenuItem } +func setDevelopmentOverrides(config *Config) error { + overrideURL, err := URL.Parse(config.BaseURL, "http://localhost:"+fmt.Sprint(config.Port)) + if err != nil { + return err + } + config.BaseURL.URL = overrideURL + return nil +} + func GetConfig() (*Config, error) { config := Config{} slog.Debug("reading config.toml") @@ -57,6 +66,12 @@ } else if errors.As(err, &tomlError) { return nil, errors.WithMessage(err, tomlError.ErrorWithUsage()) } else { return nil, errors.Wrap(err, "config error") + } + } + if os.Getenv("ENV") != "production" { + err = setDevelopmentOverrides(&config) + if err != nil { + return nil, errors.WithMessage(err, "could not override configuration") } } return &config, nil