diff options
author | Alan Pearce | 2024-04-17 19:53:22 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-17 20:53:30 +0200 |
commit | 6f6057fd56aa6d065ec59341b08cffc03619b21d (patch) | |
tree | 1776b1094f6c81e62a5cc531162c12537ca797a3 /internal/config/config.go | |
parent | 37dabe7476a9ed35a95d42ae32e3064fccbbea2d (diff) | |
download | website-6f6057fd56aa6d065ec59341b08cffc03619b21d.tar.lz website-6f6057fd56aa6d065ec59341b08cffc03619b21d.tar.zst website-6f6057fd56aa6d065ec59341b08cffc03619b21d.zip |
config: override base_url in development
Diffstat (limited to 'internal/config/config.go')
-rw-r--r-- | internal/config/config.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index cab5f90..66e3d82 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -44,6 +44,15 @@ type Config struct { 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") @@ -59,5 +68,11 @@ func GetConfig() (*Config, error) { 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 } |