Skip to content

Commit

Permalink
fix use of deprecated function
Browse files Browse the repository at this point in the history
  • Loading branch information
dhontecillas committed Jun 11, 2024
1 parent 3224a93 commit e257cbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion krakendrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Backend interface {
Store(string, interface{}) error
}

// DefaultShardedMemoryBackend is a 2018 sharded ShardedMemoryBackend
// DefaultShardedMemoryBackend is a 2048 sharded ShardedMemoryBackend
func DefaultShardedMemoryBackend(ctx context.Context) *ShardedMemoryBackend {
return NewShardedMemoryBackend(ctx, DefaultShards, DataTTL, PseudoFNV64a)
}
3 changes: 1 addition & 2 deletions memorybackend_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/sha256"
"fmt"
"io"
"math/rand"
"testing"
"time"
Expand All @@ -17,7 +16,7 @@ func generateTestKeys(num int, length int) []string {
h := sha256.New()

for i := 0; i < num; i++ {
io.WriteString(h, fmt.Sprintf("%x", r.Int()))
fmt.Fprintf(h, "%x", r.Int())
res = append(res, fmt.Sprintf("%x", h.Sum(nil))[:length])
}
return res
Expand Down
9 changes: 6 additions & 3 deletions router/gin/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func NewEndpointRateLimiterMw(tb *krakendrate.TokenBucket) EndpointMw {
//
// Deprecated: Use NewHeaderLimiterMwFromCfg instead
func NewHeaderLimiterMw(header string, maxRate float64, capacity uint64) EndpointMw {
return NewTokenLimiterMw(HeaderTokenExtractor(header), krakendrate.NewMemoryStore(maxRate, int(capacity)))
return NewTokenLimiterMw(HeaderTokenExtractor(header), krakendrate.NewMemoryStore(maxRate, int(capacity),
krakendrate.DefaultShardedMemoryBackend(context.Background())))
}

// NewHeaderLimiterMwFromCfg creates a token ratelimiter using the value of a header as a token
Expand All @@ -121,15 +122,17 @@ func NewHeaderLimiterMwFromCfg(cfg router.Config) EndpointMw {

// NewIpLimiterMw creates a token ratelimiter using the IP of the request as a token
func NewIpLimiterMw(maxRate float64, capacity uint64) EndpointMw {
return NewTokenLimiterMw(IPTokenExtractor, krakendrate.NewMemoryStore(maxRate, int(capacity)))
return NewTokenLimiterMw(IPTokenExtractor, krakendrate.NewLimiterStore(maxRate, int(capacity),
krakendrate.DefaultShardedMemoryBackend(context.Background())))
}

// NewIpLimiterWithKeyMw creates a token ratelimiter using the IP of the request as a token
//
// Deprecated: Use NewIpLimiterWithKeyMwFromCfg instead
func NewIpLimiterWithKeyMw(header string, maxRate float64, capacity uint64) EndpointMw {
tokenExtractor := NewIPTokenExtractor(header)
return NewTokenLimiterMw(tokenExtractor, krakendrate.NewMemoryStore(maxRate, int(capacity)))
return NewTokenLimiterMw(tokenExtractor, krakendrate.NewMemoryStore(maxRate, int(capacity),
krakendrate.DefaultShardedMemoryBackend(context.Background())))
}

// NewIpLimiterWithKeyMwFromCfg creates a token ratelimiter using the IP of the request as a token
Expand Down

0 comments on commit e257cbd

Please sign in to comment.