github.com/rudderlabs/rudder-go-kit@v0.30.0/throttling/options.go (about) 1 package throttling 2 3 import "github.com/go-redis/redis/v8" 4 5 // Option is a functional option for the limiter, see With* functions for reference 6 type Option func(*Limiter) 7 8 // WithInMemoryGCRA allows to use the GCRA algorithm (in-memory) with the specified burst or with the 9 // burst as rate if the provided burst is <= 0 10 func WithInMemoryGCRA(burst int64) Option { 11 return func(l *Limiter) { 12 l.useGCRA = true 13 if burst > 0 { 14 l.gcraBurst = burst 15 } 16 } 17 } 18 19 // WithRedisGCRA allows to use the GCRA algorithm (Redis version) with the specified burst or with the 20 // burst as rate if the provided burst is <= 0 21 func WithRedisGCRA(rc *redis.Client, burst int64) Option { 22 return func(l *Limiter) { 23 l.useGCRA = true 24 l.redisSpeaker = rc 25 if burst > 0 { 26 l.gcraBurst = burst 27 } 28 } 29 } 30 31 // WithRedisSortedSet allows to use the Redis SortedSet algorithm for rate limiting 32 func WithRedisSortedSet(rc *redis.Client) Option { 33 return func(l *Limiter) { 34 l.useGCRA = false 35 l.redisSpeaker = rc 36 } 37 } 38 39 // WithStatsCollector allows to setup a stats collector for the limiter 40 func WithStatsCollector(sc statsCollector) Option { 41 return func(l *Limiter) { 42 l.statsCollector = sc 43 } 44 }