Created
September 2, 2017 06:50
-
-
Save cipepser/2ae3e6047aa223568e14a7abef7bd9b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"os" | |
mgo "gopkg.in/mgo.v2" | |
"gopkg.in/mgo.v2/bson" | |
) | |
type Artist struct { | |
Name string `json:"name"` | |
Tags []struct { | |
Count int `json:"count"` | |
Value string `json:"value"` | |
} `json:"tags"` | |
Rating struct { | |
Count int `json:"count"` | |
Value int `json:"value"` | |
} `json:"rating"` | |
SortName string `json:"sort_name"` | |
Ended bool `json:"ended"` | |
Gid string `json:"gid"` | |
ID int `json:"id"` | |
Area string `json:"area"` | |
Aliases []struct { | |
Name string `json:"name"` | |
SortName string `json:"sort_name"` | |
} `json:"aliases"` | |
Begin struct { | |
Year int `json:"year"` | |
Month int `json:"month"` | |
Date int `json:"date"` | |
} `json:"begin"` | |
End struct { | |
Year int `json:"year"` | |
Month int `json:"month"` | |
Date int `json:"date"` | |
} `json:"end"` | |
Gender string `json:"gender"` | |
Type string `json:"type"` | |
} | |
func main() { | |
if len(os.Args) != 1 { | |
errors.New("please input artist name.") | |
} | |
// connect to mongodb | |
session, err := mgo.Dial("mongodb://localhost") | |
if err != nil { | |
panic(err) | |
} | |
defer session.Close() | |
db := session.DB("MusicBrainz") | |
col := db.C("artist") | |
query := col.Find(bson.M{"aliases.name": os.Args[1]}) | |
var artists []Artist | |
query.All(&artists) | |
for _, a := range artists { | |
fmt.Println(a) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment