diff --git a/internal/backends/funkwhale/client.go b/internal/backends/funkwhale/client.go index b757d6f..39071e7 100644 --- a/internal/backends/funkwhale/client.go +++ b/internal/backends/funkwhale/client.go @@ -26,8 +26,8 @@ import ( "strconv" "github.com/go-resty/resty/v2" - "go.uploadedlobster.com/scotty/internal/ratelimit" "go.uploadedlobster.com/scotty/internal/version" + "go.uploadedlobster.com/scotty/pkg/ratelimit" ) const MaxItemsPerGet = 50 diff --git a/internal/backends/listenbrainz/client.go b/internal/backends/listenbrainz/client.go index aa30b78..72257bf 100644 --- a/internal/backends/listenbrainz/client.go +++ b/internal/backends/listenbrainz/client.go @@ -27,8 +27,8 @@ import ( "time" "github.com/go-resty/resty/v2" - "go.uploadedlobster.com/scotty/internal/ratelimit" "go.uploadedlobster.com/scotty/internal/version" + "go.uploadedlobster.com/scotty/pkg/ratelimit" ) const ( diff --git a/internal/backends/spotify/client.go b/internal/backends/spotify/client.go index 08c00f3..7bbcf48 100644 --- a/internal/backends/spotify/client.go +++ b/internal/backends/spotify/client.go @@ -29,8 +29,8 @@ import ( "time" "github.com/go-resty/resty/v2" - "go.uploadedlobster.com/scotty/internal/ratelimit" "go.uploadedlobster.com/scotty/internal/version" + "go.uploadedlobster.com/scotty/pkg/ratelimit" "golang.org/x/oauth2" ) diff --git a/internal/ratelimit/httpheader.go b/pkg/ratelimit/httpheader.go similarity index 82% rename from internal/ratelimit/httpheader.go rename to pkg/ratelimit/httpheader.go index 91a05b5..3f2552c 100644 --- a/internal/ratelimit/httpheader.go +++ b/pkg/ratelimit/httpheader.go @@ -29,6 +29,15 @@ const ( MaxWaitTimeSeconds = 60 ) +// Implements rate HTTP header based limiting for resty. +// +// This works with servers that return the status code 429 (Too Many Requests) +// and an HTTP header indicating the time in seconds until rate limit resets. +// Common headers used are "X-RateLimit-Reset-In" or "Retry-After". +// +// Usage: +// +// ratelimit.EnableHTTPHeaderRateLimit(client, "Retry-After") func EnableHTTPHeaderRateLimit(client *resty.Client, resetInHeader string) { client.SetRetryCount(RetryCount) client.AddRetryCondition(