temp
This commit is contained in:
@@ -2,10 +2,10 @@ package ozon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/redis/rueidis"
|
||||
"net/http"
|
||||
"sipro-mps/internal/redis"
|
||||
"time"
|
||||
|
||||
"github.com/redis/rueidis"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -40,6 +40,7 @@ var (
|
||||
|
||||
type RateLimitTransport struct {
|
||||
http.RoundTripper
|
||||
redis rueidis.Client
|
||||
}
|
||||
|
||||
func (t *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
@@ -47,7 +48,7 @@ func (t *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error
|
||||
clientId := req.Header.Get("Client-Id")
|
||||
now := time.Now().UnixNano()
|
||||
|
||||
waitTime, err := rateLimiterScript.Exec(ctx, *redis.Client, []string{clientId}, []string{
|
||||
waitTime, err := rateLimiterScript.Exec(ctx, t.redis, []string{clientId}, []string{
|
||||
fmt.Sprintf("%d", now),
|
||||
fmt.Sprintf("%d", int64(windowSize)),
|
||||
fmt.Sprintf("%d", rps),
|
||||
@@ -61,7 +62,7 @@ func (t *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error
|
||||
}
|
||||
return t.RoundTripper.RoundTrip(req)
|
||||
}
|
||||
func NewRateLimitTransport() *RateLimitTransport {
|
||||
func NewRateLimitTransport(redis rueidis.Client) *RateLimitTransport {
|
||||
|
||||
return &RateLimitTransport{RoundTripper: http.DefaultTransport}
|
||||
return &RateLimitTransport{RoundTripper: http.DefaultTransport, redis: redis}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user