38 lines
835 B
Go
38 lines
835 B
Go
package music
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
var Releases []*MusicRelease;
|
|
var Artists []*Artist;
|
|
|
|
func make_date_work(date string) time.Time {
|
|
res, err := time.Parse("2-Jan-2006", date)
|
|
if err != nil {
|
|
fmt.Printf("somehow we failed to parse %s! falling back to epoch :]\n", date)
|
|
return time.Unix(0, 0)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func GetRelease(id string) (*MusicRelease, error) {
|
|
for _, release := range Releases {
|
|
if release.Id == id {
|
|
return release, nil
|
|
}
|
|
}
|
|
return nil, errors.New(fmt.Sprintf("Release %s not found", id))
|
|
}
|
|
|
|
func GetArtist(id string) (*Artist, error) {
|
|
for _, artist := range Artists {
|
|
if artist.Id == id {
|
|
return artist, nil
|
|
}
|
|
}
|
|
return nil, errors.New(fmt.Sprintf("Artist %s not found", id))
|
|
}
|