Documentation ¶
Overview ¶
Package mbdb contains functionality related to the MusicBrainz database.
Index ¶
- Variables
- func IsMBID(mbid string) bool
- func ShortenContext(ctx context.Context, t time.Duration) (context.Context, context.CancelFunc)
- type DB
- func (db *DB) GetArtistsFromURL(ctx context.Context, linkURL string) ([]EntityInfo, error)
- func (db *DB) GetDatabaseID(ctx context.Context, mbid string) (int32, error)
- func (db *DB) GetLabelsFromURL(ctx context.Context, linkURL string) ([]EntityInfo, error)
- func (db *DB) SetArtistsFromURLForTest(url string, artists []EntityInfo)
- func (db *DB) SetDatabaseIDForTest(mbid string, id int32)
- func (db *DB) SetLabelsFromURLForTest(url string, labels []EntityInfo)
- type EntityInfo
- type Option
Constants ¶
This section is empty.
Variables ¶
var DisallowQueries = func(db *DB) { db.disallowQueries = true }
DisallowQueries is an Option that configures DB to report an error when it would need to perform a query over the network.
Functions ¶
func IsMBID ¶
IsMBID returns true if mbid looks like a correctly-formatted MBID (i.e. a UUID). Note that this method does not check that the MBID is actually assigned to anything.
func ShortenContext ¶
ShortenContext returns a context derived from ctx with its deadline shortened by t. If ctx does not have a deadline, a derived deadline-less context is returned. The caller must call the returned cancel function to release resources.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB queries the MusicBrainz database using its API. See https://musicbrainz.org/doc/MusicBrainz_API.
func (*DB) GetArtistsFromURL ¶
GetArtistsFromURL returns artists related to linkURL. If no artist is related to the URL, an empty slice is returned.
func (*DB) GetDatabaseID ¶
GetDatabaseID returns the database ID (e.g. artist.id) corresponding to the entity with the specified MBID (e.g. artist.gid).
func (*DB) GetLabelsFromURL ¶
GetLabelsFromURL returns labels related to linkURL. If no label is related to the URL, an empty slice is returned.
func (*DB) SetArtistsFromURLForTest ¶
func (db *DB) SetArtistsFromURLForTest(url string, artists []EntityInfo)
SetArtistsFromURLForTest hardcodes artists for GetArtistsFromURL to return.
func (*DB) SetDatabaseIDForTest ¶
SetDatabaseIDForTest hardcodes an ID for GetDatabaseID to return.
func (*DB) SetLabelsFromURLForTest ¶
func (db *DB) SetLabelsFromURLForTest(url string, labels []EntityInfo)
SetLabelsFromURLForTest hardcodes labels for GetLabelsFromURL to return.
type EntityInfo ¶
type EntityInfo struct { // MBID contains the entity's UUID. MBID string // Name contains the entity's name as it appears in the database. Name string }
EntityInfo contains high-level information about an entity (e.g. artist or label). TODO: Figure out if there's some way to also get artist aliases from /ws/2/url queries.
func MakeEntityInfosForTest ¶
func MakeEntityInfosForTest(mbidNamePairs ...string) []EntityInfo
MakeEntityInfosForTest is a helper function for tests that creates EntityInfo objects given a sequence of MBID and name pairs.
type Option ¶
type Option func(db *DB)
Option can be passed to NewDB to configure the database.
func NowFunc ¶
NowFunc injects a function that is called instead of time.Now to get the current time.
func ServerURL ¶
ServerURL returns an Option that configure DB to make calls to the specified base server URL, e.g. "https://musicbrains.org" or "https://test.musicbrainz.org".