-
Notifications
You must be signed in to change notification settings - Fork 4
/
discogs.go
64 lines (59 loc) · 1.42 KB
/
discogs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"github.com/cenkalti/backoff/v4"
"github.com/irlndts/go-discogs"
"github.com/pkg/errors"
"net/http"
"strconv"
"strings"
)
var (
RetryCode = strconv.Itoa(http.StatusTooManyRequests)
)
func (client *App) GetRelease(id int) (resp *discogs.Release, err error) {
err = backoff.Retry(func() error {
resp, err = client.Discogs.Release(id)
if err != nil && strings.Contains(err.Error(), RetryCode) {
return err // retry
}
return nil
}, client.Backoff)
client.Backoff.Reset()
if resp == nil {
err = errors.New("retries exceeded")
}
return
}
func (client *App) GetLabelReleases(page, label int) (resp *discogs.LabelReleases, err error) {
err = backoff.Retry(func() error {
resp, err = client.Discogs.LabelReleases(label, &discogs.Pagination{
Sort: "year",
SortOrder: "asc",
PerPage: 25,
Page: page,
})
if err != nil && strings.Contains(err.Error(), RetryCode) {
return err // retry
}
return nil
}, client.Backoff)
client.Backoff.Reset()
if resp == nil {
err = errors.New("retries exceeded")
}
return
}
func (client *App) GetLabel(label int) (resp *discogs.Label, err error) {
err = backoff.Retry(func() error {
resp, err = client.Discogs.Label(label)
if err != nil && strings.Contains(err.Error(), RetryCode) {
return err // retry
}
return nil
}, client.Backoff)
client.Backoff.Reset()
if resp == nil {
err = errors.New("retries exceeded")
}
return
}