Minor improvements
This commit is contained in:
		@@ -4,6 +4,8 @@
 | 
			
		||||
 | 
			
		||||
go-discogs is a Go client library for the [Discogs API](https://www.discogs.com/developers/). Check the usage section to see how to access the Discogs API.
 | 
			
		||||
 | 
			
		||||
The lib is under MIT but be sure you are familiar with [Discogs API Terms of Use](https://support.discogs.com/hc/en-us/articles/360009334593-API-Terms-of-Use).
 | 
			
		||||
 | 
			
		||||
### Feauteres
 | 
			
		||||
 * Database
 | 
			
		||||
  * [Releases](#releases)
 | 
			
		||||
@@ -31,10 +33,11 @@ import "github.com/irlndts/go-discogs"
 | 
			
		||||
Some requests require authentification (as any user). According to [Discogs](https://www.discogs.com/developers/#page:authentication,header:authentication-discogs-auth-flow), to send requests with Discogs Auth, you have two options: sending your credentials in the query string with key and secret parameters or a [token parameter](https://www.discogs.com/settings/developers).
 | 
			
		||||
This is token way example:
 | 
			
		||||
```go
 | 
			
		||||
client, err := discogs.NewClient(&discogs.Options{
 | 
			
		||||
client, err := discogs.New(&discogs.Options{
 | 
			
		||||
        UserAgent: "Some Name",
 | 
			
		||||
        Currency:  "EUR", // optional, "USD" (default), "GBP", "EUR", "CAD", "AUD", "JPY", "CHF", "MXN", "BRL", "NZD", "SEK", "ZAR" are allowed
 | 
			
		||||
        Token:     "Some Token", // optional
 | 
			
		||||
        URL:       "https://api.discogs.com", // optional
 | 
			
		||||
    })
 | 
			
		||||
``` 
 | 
			
		||||
 | 
			
		||||
@@ -85,5 +88,3 @@ Example
 | 
			
		||||
    fmt.Println(r.Title)
 | 
			
		||||
  }
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
etc. 
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								discogs.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								discogs.go
									
									
									
									
									
								
							@@ -14,22 +14,26 @@ const (
 | 
			
		||||
 | 
			
		||||
// Options is a set of options to use discogs API client
 | 
			
		||||
type Options struct {
 | 
			
		||||
	URL       string
 | 
			
		||||
	Currency  string
 | 
			
		||||
	// Discogs API endpoint (optional).
 | 
			
		||||
	URL string
 | 
			
		||||
	// Currency to use (optional, default is USD).
 | 
			
		||||
	Currency string
 | 
			
		||||
	// UserAgent to to call discogs api with.
 | 
			
		||||
	UserAgent string
 | 
			
		||||
	Token     string
 | 
			
		||||
	// Token provided by discogs (optional).
 | 
			
		||||
	Token string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Client is a Discogs client for making Discogs API requests.
 | 
			
		||||
type Client struct {
 | 
			
		||||
// Discogs is a Discogs' client for making Discogs API requests.
 | 
			
		||||
type Discogs struct {
 | 
			
		||||
	Database *DatabaseService
 | 
			
		||||
	Search   *SearchService
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var header *http.Header
 | 
			
		||||
 | 
			
		||||
// NewClient returns a new Client.
 | 
			
		||||
func NewClient(o *Options) (*Client, error) {
 | 
			
		||||
// New returns a new discogs API client.
 | 
			
		||||
func New(o *Options) (*Discogs, error) {
 | 
			
		||||
	header = &http.Header{}
 | 
			
		||||
 | 
			
		||||
	if o == nil || o.UserAgent == "" {
 | 
			
		||||
@@ -52,7 +56,7 @@ func NewClient(o *Options) (*Client, error) {
 | 
			
		||||
		o.URL = discogsAPI
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &Client{
 | 
			
		||||
	return &Discogs{
 | 
			
		||||
		Database: newDatabaseService(o.URL, cur),
 | 
			
		||||
		Search:   newSearchService(o.URL + "/database/search"),
 | 
			
		||||
	}, nil
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ const (
 | 
			
		||||
	testToken     = ""
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func initDiscogsClient(t *testing.T, options *Options) *Client {
 | 
			
		||||
func initDiscogsClient(t *testing.T, options *Options) *Discogs {
 | 
			
		||||
	if options == nil {
 | 
			
		||||
		options = &Options{
 | 
			
		||||
			UserAgent: testUserAgent,
 | 
			
		||||
@@ -22,7 +22,7 @@ func initDiscogsClient(t *testing.T, options *Options) *Client {
 | 
			
		||||
		options.UserAgent = testUserAgent
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	client, err := NewClient(options)
 | 
			
		||||
	client, err := New(options)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("failed to create client: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -30,7 +30,7 @@ func initDiscogsClient(t *testing.T, options *Options) *Client {
 | 
			
		||||
	return client
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestNewClient(t *testing.T) {
 | 
			
		||||
func TestNew(t *testing.T) {
 | 
			
		||||
	tests := map[string]struct {
 | 
			
		||||
		options *Options
 | 
			
		||||
		err     error
 | 
			
		||||
@@ -53,7 +53,7 @@ func TestNewClient(t *testing.T) {
 | 
			
		||||
	for name := range tests {
 | 
			
		||||
		tt := tests[name]
 | 
			
		||||
		t.Run(name, func(t *testing.T) {
 | 
			
		||||
			if _, err := NewClient(tt.options); err != tt.err {
 | 
			
		||||
			if _, err := New(tt.options); err != tt.err {
 | 
			
		||||
				t.Errorf("err got=%s; want=%s", err, tt.err)
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	d, err := discogs.NewClient(&discogs.Options{
 | 
			
		||||
	d, err := discogs.New(&discogs.Options{
 | 
			
		||||
		UserAgent: "TestDiscogsClient/0.0.1 +http://example.com",
 | 
			
		||||
		Currency:  "USD",
 | 
			
		||||
		Token:     "",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user