all repos — website @ 60251afdc19df17428a41418ba04fdf322d35b0d

My website

server: use switch statement to satisfy gocritic

Alan Pearce
commit

60251afdc19df17428a41418ba04fdf322d35b0d

parent

8a0bd203ade09dec8efdc30381e8348d04d4e3ec

1 file changed, 10 insertions(+), 5 deletions(-)

changed files
M internal/server/server.gointernal/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) } })