🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
More slices instead of pointers of slice
Deluan27b7b7ce086e
diff --git a/api/album_list.go b/api/album_list.goindex a4ee8b5d9..3f761aacc 100644--- a/api/album_list.go+++ b/api/album_list.go@@ -16,17 +16,17 @@ type AlbumListController struct {types map[string]strategy}-type strategy func(offset int, size int) (*domain.Albums, error)+type strategy func(offset int, size int) (domain.Albums, error)func (c *AlbumListController) Prepare() {utils.ResolveDependencies(&c.listGen)c.types = map[string]strategy{- "random": func(o int, s int) (*domain.Albums, error) { return c.listGen.GetRandom(o, s) },- "newest": func(o int, s int) (*domain.Albums, error) { return c.listGen.GetNewest(o, s) },- "recent": func(o int, s int) (*domain.Albums, error) { return c.listGen.GetRecent(o, s) },- "frequent": func(o int, s int) (*domain.Albums, error) { return c.listGen.GetFrequent(o, s) },- "highest": func(o int, s int) (*domain.Albums, error) { return c.listGen.GetHighest(o, s) },+ "random": func(o int, s int) (domain.Albums, error) { return c.listGen.GetRandom(o, s) },+ "newest": func(o int, s int) (domain.Albums, error) { return c.listGen.GetNewest(o, s) },+ "recent": func(o int, s int) (domain.Albums, error) { return c.listGen.GetRecent(o, s) },+ "frequent": func(o int, s int) (domain.Albums, error) { return c.listGen.GetFrequent(o, s) },+ "highest": func(o int, s int) (domain.Albums, error) { return c.listGen.GetHighest(o, s) },}}@@ -48,9 +48,9 @@ func (c *AlbumListController) GetAlbumList() {c.SendError(responses.ERROR_GENERIC, "Internal Error")}- albumList := make([]responses.Child, len(*albums))+ albumList := make([]responses.Child, len(albums))- for i, al := range *albums {+ for i, al := range albums {albumList[i].Id = al.IdalbumList[i].Title = al.NamealbumList[i].Parent = al.ArtistId@@ -80,9 +80,9 @@ func (c *AlbumListController) GetStarred() {response := c.NewEmpty()response.Starred = &responses.Starred{}- response.Starred.Album = make([]responses.Child, len(*albums))+ response.Starred.Album = make([]responses.Child, len(albums))- for i, entry := range *albums {+ for i, entry := range albums {response.Starred.Album[i] = c.ToChild(entry)}@@ -98,8 +98,8 @@ func (c *AlbumListController) GetNowPlaying() {response := c.NewEmpty()response.NowPlaying = &responses.NowPlaying{}- response.NowPlaying.Entry = make([]responses.NowPlayingEntry, len(*npInfos))- for i, entry := range *npInfos {+ response.NowPlaying.Entry = make([]responses.NowPlayingEntry, len(npInfos))+ for i, entry := range npInfos {response.NowPlaying.Entry[i].Child = c.ToChild(entry)response.NowPlaying.Entry[i].UserName = entry.UserNameresponse.NowPlaying.Entry[i].MinutesAgo = entry.MinutesAgodiff --git a/domain/album.go b/domain/album.goindex bef266f17..bc92631ad 100644--- a/domain/album.go+++ b/domain/album.go@@ -28,8 +28,8 @@ type AlbumRepository interface {Put(m *Album) errorGet(id string) (*Album, error)FindByArtist(artistId string) (*Albums, error)- GetAll(QueryOptions) (*Albums, error)+ GetAll(QueryOptions) (Albums, error)PurgeInactive(active Albums) ([]string, error)- GetAllIds() (*[]string, error)+ GetAllIds() ([]string, error)GetStarred(QueryOptions) (*Albums, error)}diff --git a/engine/list_generator.go b/engine/list_generator.goindex eafa56789..6af9c6d73 100644--- a/engine/list_generator.go+++ b/engine/list_generator.go@@ -10,13 +10,13 @@ import (// TODO Use Entries instead of Albumstype ListGenerator interface {- GetNewest(offset int, size int) (*domain.Albums, error)- GetRecent(offset int, size int) (*domain.Albums, error)- GetFrequent(offset int, size int) (*domain.Albums, error)- GetHighest(offset int, size int) (*domain.Albums, error)- GetRandom(offset int, size int) (*domain.Albums, error)- GetStarred() (*Entries, error)- GetNowPlaying() (*Entries, error)+ GetNewest(offset int, size int) (domain.Albums, error)+ GetRecent(offset int, size int) (domain.Albums, error)+ GetFrequent(offset int, size int) (domain.Albums, error)+ GetHighest(offset int, size int) (domain.Albums, error)+ GetRandom(offset int, size int) (domain.Albums, error)+ GetStarred() (Entries, error)+ GetNowPlaying() (Entries, error)}func NewListGenerator(alr domain.AlbumRepository, mfr domain.MediaFileRepository, npr NowPlayingRepository) ListGenerator {@@ -29,53 +29,53 @@ type listGenerator struct {npRepo NowPlayingRepository}-func (g listGenerator) query(qo domain.QueryOptions, offset int, size int) (*domain.Albums, error) {+func (g listGenerator) query(qo domain.QueryOptions, offset int, size int) (domain.Albums, error) {qo.Offset = offsetqo.Size = sizereturn g.albumRepo.GetAll(qo)}-func (g listGenerator) GetNewest(offset int, size int) (*domain.Albums, error) {+func (g listGenerator) GetNewest(offset int, size int) (domain.Albums, error) {qo := domain.QueryOptions{SortBy: "CreatedAt", Desc: true, Alpha: true}return g.query(qo, offset, size)}-func (g listGenerator) GetRecent(offset int, size int) (*domain.Albums, error) {+func (g listGenerator) GetRecent(offset int, size int) (domain.Albums, error) {qo := domain.QueryOptions{SortBy: "PlayDate", Desc: true, Alpha: true}return g.query(qo, offset, size)}-func (g listGenerator) GetFrequent(offset int, size int) (*domain.Albums, error) {+func (g listGenerator) GetFrequent(offset int, size int) (domain.Albums, error) {qo := domain.QueryOptions{SortBy: "PlayCount", Desc: true}return g.query(qo, offset, size)}-func (g listGenerator) GetHighest(offset int, size int) (*domain.Albums, error) {+func (g listGenerator) GetHighest(offset int, size int) (domain.Albums, error) {qo := domain.QueryOptions{SortBy: "Rating", Desc: true}return g.query(qo, offset, size)}-func (g listGenerator) GetRandom(offset int, size int) (*domain.Albums, error) {+func (g listGenerator) GetRandom(offset int, size int) (domain.Albums, error) {ids, err := g.albumRepo.GetAllIds()if err != nil {return nil, err}- size = utils.MinInt(size, len(*ids))+ size = utils.MinInt(size, len(ids))perm := rand.Perm(size)r := make(domain.Albums, size)for i := 0; i < size; i++ {v := perm[i]- al, err := g.albumRepo.Get((*ids)[v])+ al, err := g.albumRepo.Get((ids)[v])if err != nil {return nil, err}r[i] = *al}- return &r, nil+ return r, nil}-func (g listGenerator) GetStarred() (*Entries, error) {+func (g listGenerator) GetStarred() (Entries, error) {albums, err := g.albumRepo.GetStarred(domain.QueryOptions{})if err != nil {return nil, err@@ -86,10 +86,10 @@ func (g listGenerator) GetStarred() (*Entries, error) {entries[i] = FromAlbum(&al)}- return &entries, nil+ return entries, nil}-func (g listGenerator) GetNowPlaying() (*Entries, error) {+func (g listGenerator) GetNowPlaying() (Entries, error) {npInfo, err := g.npRepo.GetAll()if err != nil {return nil, err@@ -107,5 +107,5 @@ func (g listGenerator) GetNowPlaying() (*Entries, error) {entries[i].PlayerName = np.PlayerName}- return &entries, nil+ return entries, nil}diff --git a/persistence/album_repository.go b/persistence/album_repository.goindex dded4b361..827700f14 100644--- a/persistence/album_repository.go+++ b/persistence/album_repository.go@@ -35,13 +35,13 @@ func (r *albumRepository) FindByArtist(artistId string) (*domain.Albums, error)return &as, err}-func (r *albumRepository) GetAll(options domain.QueryOptions) (*domain.Albums, error) {+func (r *albumRepository) GetAll(options domain.QueryOptions) (domain.Albums, error) {var as = make(domain.Albums, 0)err := r.loadAll(&as, options)- return &as, err+ return as, err}-func (r *albumRepository) GetAllIds() (*[]string, error) {+func (r *albumRepository) GetAllIds() ([]string, error) {idMap, err := r.getAllIds()if err != nil {return nil, err@@ -54,7 +54,7 @@ func (r *albumRepository) GetAllIds() (*[]string, error) {i++}- return &ids, nil+ return ids, nil}func (r *albumRepository) PurgeInactive(active domain.Albums) ([]string, error) {diff --git a/persistence/mock_album_repo.go b/persistence/mock_album_repo.goindex 38d37c56c..bc611c151 100644--- a/persistence/mock_album_repo.go+++ b/persistence/mock_album_repo.go@@ -51,12 +51,12 @@ func (m *MockAlbum) Get(id string) (*domain.Album, error) {return nil, domain.ErrNotFound}-func (m *MockAlbum) GetAll(qo domain.QueryOptions) (*domain.Albums, error) {+func (m *MockAlbum) GetAll(qo domain.QueryOptions) (domain.Albums, error) {m.Options = qoif m.err {return nil, errors.New("Error!")}- return &m.all, nil+ return m.all, nil}func (m *MockAlbum) FindByArtist(artistId string) (*domain.Albums, error) {