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:
parent
82fd17c836
commit
21912d4ec2
17 changed files with 102 additions and 469 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue