-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't figure out how to use Relationships #7
Comments
Hej and sorry for my late response. The problem in your example is, you are trying to cast an interface type to a struct. gomusicbrainz.Relation is an interface type that only requires the TypeOf() method to be implemented on the actual type. type Relation interface {
TypeOf() string
} What you want to do is a type assertion. Whenever you have an interface and want to access it's 'underlying' type, you have to assert the actual type. Here is a small example that requests an artist and prints it's URL relations package main
import (
"fmt"
"gomusicbrainz"
)
func main() {
client, _ := gomusicbrainz.NewWS2Client(
"https://musicbrainz.org/ws/2",
"A GoMusicBrainz example",
"0",
"http://github.com/michiwend/gomusicbrainz")
artist, err := client.LookupArtist(
gomusicbrainz.MBID("fe1a873d-2000-4789-a895-4187fe756203"),
"url-rels")
if err != nil {
fmt.Println(err)
return
}
if urlRels, ok := artist.Relations["url"]; ok {
for _, rel := range urlRels {
// type assertion
urlRelation, ok := rel.(*gomusicbrainz.URLRelation)
if !ok {
fmt.Println("should not have happend!")
continue
}
fmt.Printf("%s: %s\n", urlRelation.Type, urlRelation.Target)
}
}
} |
Thank you! A little late and figured out another solution, but thanks for enlightening me! |
Hey!
I've been working on this for a few days and can't really figure it out.
In general, my goal is to give gomusicbrainz a MBID and get returned the URL relationships (Wikipedia, official website, Spotify, etc..).
For instance, this is my best try:
My question is: How do I convert a
gomusicbrainz.Relation
togomusicbrainz.URLRelation
?The text was updated successfully, but these errors were encountered: