MusicBrainz web service package for Go

As part of some side project using Go I implemented the musicbrainzws2 package. It wraps the MusicBrainz web service and search API into a Go friendly interface. I think it is currently the most complete MB API wrapper for Go.

The package is I think rather feature complete, but likely there are bugs and in the current state I reserve the freedom to change the interface at any time as I see fit.

If you are doing some MB project with Go you might want to consider this package.

Documentation: musicbrainzws2 package - go.uploadedlobster.com/musicbrainzws2 - Go Packages
Source code: ~phw/go-musicbrainzws2 - Go package to access the MusicBrainz Web Service v2 - sourcehut git

7 Likes

Nice! A few high-level Go suggestions (let me know if there’s a better place for this):

  • NewClient should probably return a *Client rather than a Client, and all of the methods on Client should probably have *Client receiver types rather than Client. Using pointers allows methods to modify the receiver (which SetUserAgent currently does – it only works because it’s updating the httpClient pointer field). See https://go.dev/tour/methods/4 and https://go.dev/tour/methods/8 for more details.
  • It might be clearer if the names of Result structs matched the methods that return them, e.g. BrowseRecordings could return BrowseRecordingsResult instead of RecordingBrowseResult (the current names are also singular instead of plural).
2 Likes

Thanks a lot for looking into this. I agree with both parts and have updated the code accordingly.

Regarding the receiver I originally intentionally did not use pointers as none of the methods is supposed to modify the client struct directly. But it probably makes sense, if only for consistency and retain the option to have data stored on the client struct.

2 Likes