From 60251afdc19df17428a41418ba04fdf322d35b0d Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 6 Dec 2024 20:33:13 +0100 Subject: server: use switch statement to satisfy gocritic --- internal/server/server.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'internal/server/server.go') 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) } }) -- cgit 1.4.1