navidrome/model/get_entity.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
688 B
Go
Raw Normal View History

package model
2020-10-20 13:38:44 -04:00
import (
"context"
"errors"
2020-10-20 13:38:44 -04:00
)
// TODO: Should the type be encoded in the ID?
2026-02-08 08:57:30 -06:00
func GetEntityByID(ctx context.Context, ds DataStore, id string) (any, error) {
getters := []func() (any, error){
func() (any, error) { return ds.Artist(ctx).Get(id) },
func() (any, error) { return ds.Album(ctx).Get(id) },
func() (any, error) { return ds.Playlist(ctx).Get(id) },
func() (any, error) { return ds.MediaFile(ctx).Get(id) },
func() (any, error) { return ds.Radio(ctx).Get(id) },
2020-10-20 13:38:44 -04:00
}
for _, get := range getters {
entity, err := get()
if err == nil {
return entity, nil
}
if !errors.Is(err, ErrNotFound) {
return nil, err
}
2020-10-20 13:38:44 -04:00
}
return nil, ErrNotFound
2020-10-20 13:38:44 -04:00
}