mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-10 23:49:28 +02:00
Moved ratelimit to pkg
This commit is contained in:
parent
c4da3a40cc
commit
6ac2b4f142
4 changed files with 12 additions and 3 deletions
|
@ -26,8 +26,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"go.uploadedlobster.com/scotty/internal/ratelimit"
|
|
||||||
"go.uploadedlobster.com/scotty/internal/version"
|
"go.uploadedlobster.com/scotty/internal/version"
|
||||||
|
"go.uploadedlobster.com/scotty/pkg/ratelimit"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MaxItemsPerGet = 50
|
const MaxItemsPerGet = 50
|
||||||
|
|
|
@ -27,8 +27,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"go.uploadedlobster.com/scotty/internal/ratelimit"
|
|
||||||
"go.uploadedlobster.com/scotty/internal/version"
|
"go.uploadedlobster.com/scotty/internal/version"
|
||||||
|
"go.uploadedlobster.com/scotty/pkg/ratelimit"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -29,8 +29,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"go.uploadedlobster.com/scotty/internal/ratelimit"
|
|
||||||
"go.uploadedlobster.com/scotty/internal/version"
|
"go.uploadedlobster.com/scotty/internal/version"
|
||||||
|
"go.uploadedlobster.com/scotty/pkg/ratelimit"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,15 @@ const (
|
||||||
MaxWaitTimeSeconds = 60
|
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) {
|
func EnableHTTPHeaderRateLimit(client *resty.Client, resetInHeader string) {
|
||||||
client.SetRetryCount(RetryCount)
|
client.SetRetryCount(RetryCount)
|
||||||
client.AddRetryCondition(
|
client.AddRetryCondition(
|
Loading…
Add table
Reference in a new issue