refactor mux path routes

legend has it that if you refactor your code enough times, one day you
will finally be happy
This commit is contained in:
ari melody 2025-11-07 17:48:06 +00:00
parent 82fd17c836
commit 21912d4ec2
Signed by: ari
GPG key ID: CF99829C92678188
17 changed files with 102 additions and 469 deletions

View file

@ -4,7 +4,6 @@ import (
"fmt"
"net/http"
"os"
"strings"
"arimelody-web/admin/core"
"arimelody-web/admin/templates"
@ -16,14 +15,6 @@ func serveArtists(app *model.AppState) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value("session").(*model.Session)
slices := strings.Split(strings.TrimPrefix(r.URL.Path, "/artists")[1:], "/")
artistID := slices[0]
if len(artistID) > 0 {
serveArtist(app, artistID).ServeHTTP(w, r)
return
}
artists, err := controller.GetAllArtists(app.DB)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artists: %s\n", err)