server: use switch statement to satisfy gocritic
1 file changed, 10 insertions(+), 5 deletions(-)
changed files
M internal/server/server.go → internal/server/server.go
@@ -190,15 +190,20 @@ ) 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) } })