diff options
author | Alan Pearce | 2024-12-06 20:33:13 +0100 |
---|---|---|
committer | Alan Pearce | 2024-12-06 20:33:13 +0100 |
commit | 60251afdc19df17428a41418ba04fdf322d35b0d (patch) | |
tree | 640e6dc13c8007e7db3bc1a2794f3c8f5e7f2ff2 /internal | |
parent | 8a0bd203ade09dec8efdc30381e8348d04d4e3ec (diff) | |
download | website-60251afdc19df17428a41418ba04fdf322d35b0d.tar.lz website-60251afdc19df17428a41418ba04fdf322d35b0d.tar.zst website-60251afdc19df17428a41418ba04fdf322d35b0d.zip |
server: use switch statement to satisfy gocritic
Diffstat (limited to 'internal')
-rw-r--r-- | internal/server/server.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/internal/server/server.go b/internal/server/server.go index ba825aa..21c7743 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -190,15 +190,20 @@ func New(runtimeConfig *Config, log *log.Logger) (*Server, error) { replace := "${1}." + config.Domains[0] loggingMux.Handle(config.BaseURL.Hostname()+"/", mux) loggingMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if slices.Contains(config.Domains, r.Host) { + switch true { + case slices.Contains(config.Domains, r.Host): path, _ := website.CanonicalisePath(r.URL.Path) - newURL := config.BaseURL.JoinPath(path) - http.Redirect(w, r, newURL.String(), http.StatusMovedPermanently) - } else if re.MatchString(r.Host) { + http.Redirect( + w, + r, + config.BaseURL.JoinPath(path).String(), + http.StatusMovedPermanently, + ) + case re.MatchString(r.Host): url := config.BaseURL url.Host = re.ReplaceAllString(r.Host, replace) http.Redirect(w, r, url.String(), http.StatusTemporaryRedirect) - } else { + case true: http.NotFound(w, r) } }) |