package admin import ( "fmt" "net/http" "strings" "arimelody-web/global" "arimelody-web/music/model" "arimelody-web/music/controller" ) func serveArtist() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { slices := strings.Split(r.URL.Path[1:], "/") id := slices[0] artist, err := music.GetArtist(global.DB, id) if err != nil { if artist == nil { http.NotFound(w, r) return } fmt.Printf("Error rendering admin artist page for %s: %s\n", id, err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } credits, err := music.GetArtistCredits(global.DB, artist.ID) if err != nil { fmt.Printf("Error rendering admin track page for %s: %s\n", id, err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } type Artist struct { *model.Artist Credits []*model.Credit } err = pages["artist"].Execute(w, Artist{ Artist: artist, Credits: credits }) if err != nil { fmt.Printf("Error rendering admin track page for %s: %s\n", id, err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) } }) }