use pointers to specid.ID in spec responses
a bit shit but this way we can have a nil value of ID so that the json emitempty tag will do the thing
This commit is contained in:
@@ -265,7 +265,7 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
similar := &spec.SimilarArtist{
|
similar := &spec.SimilarArtist{
|
||||||
ID: specid.ID{Type: specid.Artist, Value: -1},
|
ID: &specid.ID{Type: specid.Artist, Value: -1},
|
||||||
}
|
}
|
||||||
if artist.ID != 0 {
|
if artist.ID != 0 {
|
||||||
similar.ID = artist.SID()
|
similar.ID = artist.SID()
|
||||||
|
|||||||
@@ -91,15 +91,15 @@ type Albums struct {
|
|||||||
|
|
||||||
type Album struct {
|
type Album struct {
|
||||||
// common
|
// common
|
||||||
ID specid.ID `xml:"id,attr,omitempty" json:"id"`
|
ID *specid.ID `xml:"id,attr,omitempty" json:"id"`
|
||||||
CoverID specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
CoverID *specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||||
ArtistID specid.ID `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
ArtistID *specid.ID `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
||||||
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
||||||
// browsing by folder (eg. getAlbumList)
|
// browsing by folder (eg. getAlbumList)
|
||||||
Title string `xml:"title,attr" json:"title"`
|
Title string `xml:"title,attr" json:"title"`
|
||||||
Album string `xml:"album,attr" json:"album"`
|
Album string `xml:"album,attr" json:"album"`
|
||||||
ParentID specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
ParentID *specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||||
IsDir bool `xml:"isDir,attr,omitempty" json:"isDir,omitempty"`
|
IsDir bool `xml:"isDir,attr,omitempty" json:"isDir,omitempty"`
|
||||||
// browsing by tags (eg. getAlbumList2)
|
// browsing by tags (eg. getAlbumList2)
|
||||||
Name string `xml:"name,attr" json:"name"`
|
Name string `xml:"name,attr" json:"name"`
|
||||||
TrackCount int `xml:"songCount,attr" json:"songCount"`
|
TrackCount int `xml:"songCount,attr" json:"songCount"`
|
||||||
@@ -119,27 +119,27 @@ type TracksByGenre struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TrackChild struct {
|
type TrackChild struct {
|
||||||
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
|
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
|
||||||
AlbumID specid.ID `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
|
AlbumID *specid.ID `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
|
||||||
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
||||||
ArtistID specid.ID `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
ArtistID *specid.ID `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
||||||
Bitrate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
|
Bitrate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
|
||||||
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
|
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
|
||||||
CoverID specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
CoverID *specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||||
CreatedAt time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
|
CreatedAt time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
|
||||||
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
|
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
|
||||||
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
|
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
|
||||||
ID specid.ID `xml:"id,attr,omitempty" json:"id,omitempty"`
|
ID *specid.ID `xml:"id,attr,omitempty" json:"id,omitempty"`
|
||||||
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
||||||
IsVideo bool `xml:"isVideo,attr" json:"isVideo"`
|
IsVideo bool `xml:"isVideo,attr" json:"isVideo"`
|
||||||
ParentID specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
ParentID *specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||||
Path string `xml:"path,attr,omitempty" json:"path,omitempty"`
|
Path string `xml:"path,attr,omitempty" json:"path,omitempty"`
|
||||||
Size int `xml:"size,attr,omitempty" json:"size,omitempty"`
|
Size int `xml:"size,attr,omitempty" json:"size,omitempty"`
|
||||||
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
|
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
|
||||||
Title string `xml:"title,attr" json:"title"`
|
Title string `xml:"title,attr" json:"title"`
|
||||||
TrackNumber int `xml:"track,attr,omitempty" json:"track,omitempty"`
|
TrackNumber int `xml:"track,attr,omitempty" json:"track,omitempty"`
|
||||||
DiscNumber int `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"`
|
DiscNumber int `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"`
|
||||||
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
|
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Artists struct {
|
type Artists struct {
|
||||||
@@ -148,11 +148,11 @@ type Artists struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Artist struct {
|
type Artist struct {
|
||||||
ID specid.ID `xml:"id,attr,omitempty" json:"id"`
|
ID *specid.ID `xml:"id,attr,omitempty" json:"id"`
|
||||||
Name string `xml:"name,attr" json:"name"`
|
Name string `xml:"name,attr" json:"name"`
|
||||||
CoverID specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
CoverID *specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||||
AlbumCount int `xml:"albumCount,attr" json:"albumCount"`
|
AlbumCount int `xml:"albumCount,attr" json:"albumCount"`
|
||||||
Albums []*Album `xml:"album,omitempty" json:"album,omitempty"`
|
Albums []*Album `xml:"album,omitempty" json:"album,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Indexes struct {
|
type Indexes struct {
|
||||||
@@ -167,8 +167,8 @@ type Index struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Directory struct {
|
type Directory struct {
|
||||||
ID specid.ID `xml:"id,attr,omitempty" json:"id"`
|
ID *specid.ID `xml:"id,attr,omitempty" json:"id"`
|
||||||
ParentID specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
ParentID *specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||||
Name string `xml:"name,attr,omitempty" json:"name"`
|
Name string `xml:"name,attr,omitempty" json:"name"`
|
||||||
Starred string `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
Starred string `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||||
Children []*TrackChild `xml:"child,omitempty" json:"child,omitempty"`
|
Children []*TrackChild `xml:"child,omitempty" json:"child,omitempty"`
|
||||||
@@ -239,9 +239,9 @@ type Playlist struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SimilarArtist struct {
|
type SimilarArtist struct {
|
||||||
ID specid.ID `xml:"id,attr" json:"id"`
|
ID *specid.ID `xml:"id,attr" json:"id"`
|
||||||
Name string `xml:"name,attr" json:"name"`
|
Name string `xml:"name,attr" json:"name"`
|
||||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistInfo struct {
|
type ArtistInfo struct {
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ type Artist struct {
|
|||||||
AlbumCount int `sql:"-"`
|
AlbumCount int `sql:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Artist) SID() specid.ID {
|
func (a *Artist) SID() *specid.ID {
|
||||||
return specid.ID{Type: specid.Artist, Value: a.ID}
|
return &specid.ID{Type: specid.Artist, Value: a.ID}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Artist) IndexName() string {
|
func (a *Artist) IndexName() string {
|
||||||
@@ -92,16 +92,16 @@ type Track struct {
|
|||||||
TagBrainzID string `sql:"default: null"`
|
TagBrainzID string `sql:"default: null"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Track) SID() specid.ID {
|
func (t *Track) SID() *specid.ID {
|
||||||
return specid.ID{Type: specid.Track, Value: t.ID}
|
return &specid.ID{Type: specid.Track, Value: t.ID}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Track) AlbumSID() specid.ID {
|
func (t *Track) AlbumSID() *specid.ID {
|
||||||
return specid.ID{Type: specid.Album, Value: t.AlbumID}
|
return &specid.ID{Type: specid.Album, Value: t.AlbumID}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Track) ArtistSID() specid.ID {
|
func (t *Track) ArtistSID() *specid.ID {
|
||||||
return specid.ID{Type: specid.Artist, Value: t.ArtistID}
|
return &specid.ID{Type: specid.Artist, Value: t.ArtistID}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Track) Ext() string {
|
func (t *Track) Ext() string {
|
||||||
@@ -176,12 +176,12 @@ type Album struct {
|
|||||||
ReceivedTags bool `gorm:"-"`
|
ReceivedTags bool `gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Album) SID() specid.ID {
|
func (a *Album) SID() *specid.ID {
|
||||||
return specid.ID{Type: specid.Album, Value: a.ID}
|
return &specid.ID{Type: specid.Album, Value: a.ID}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Album) ParentSID() specid.ID {
|
func (a *Album) ParentSID() *specid.ID {
|
||||||
return specid.ID{Type: specid.Album, Value: a.ParentID}
|
return &specid.ID{Type: specid.Album, Value: a.ParentID}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Album) IndexRightPath() string {
|
func (a *Album) IndexRightPath() string {
|
||||||
|
|||||||
Reference in New Issue
Block a user