func (h AlbumHandler) getAlbum(w http.ResponseWriter, categoryName string, artistName string, albumName string) { log.Printf("Looking up album '%s/%s/%s\n", categoryName, artistName, albumName) album, err := model.GetAlbum(h.Music, categoryName, artistName, albumName) if err == nil { log.Printf("Found album: %s/%s; %d tracks", album.Artist, album.Name, len(album.Tracks)) summary := model.NewAlbumSummary(album) j, _ := json.Marshal(summary) w.Write(j) return } log.Printf("Did not find album: %s/%s/%s (%v)", categoryName, artistName, albumName, err) //fmt.Fprintf(w, "\n<h1>Hello</h1><div>world</div>\n") writeError(w, http.StatusNotFound, fmt.Sprintf("Album not found '%s'", albumName)) }
func (h AlbumHandler) getAlbum(w http.ResponseWriter, categoryName string, artistName string, albumName string) { log.Printf("Looking up album '%s/%s/%s\n", categoryName, artistName, albumName) music, err := h.GetCollection() if err != nil { log.Printf("Failed to connect to mpd") writeError(w, http.StatusNotFound, "Problem with mpd") } album, err := model.GetAlbum(music, categoryName, artistName, albumName) if err == nil { log.Printf("Found album: %s/%s; %d tracks", album.Artist, album.Name, len(album.Tracks)) summary := model.NewAlbumSummary(album) j, _ := json.Marshal(summary) w.Write(j) return } log.Printf("Did not find album: %s/%s/%s (%v)", categoryName, artistName, albumName, err) writeError(w, http.StatusNotFound, fmt.Sprintf("Album not found '%s'", albumName)) }