mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-21 16:17:13 +00:00
refactor limit functions
This commit is contained in:
parent
da46e23ae0
commit
b22fbe6aa8
@ -32,7 +32,7 @@ type RateLimiter struct {
|
||||
var rateLimiterInstance *RateLimiter
|
||||
var rateOnce sync.Once
|
||||
|
||||
func SetupRateLimiter(cfg *config.ServerConfig) {
|
||||
func SetRateLimit(cfg *config.ServerConfig) {
|
||||
rateLimiter := NewRateLimiter(
|
||||
rate.Limit(cfg.RateLimit.WsLimit),
|
||||
cfg.RateLimit.WsBurst,
|
||||
|
@ -12,13 +12,13 @@ type SizeLimiter struct {
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func SetupSizeLimiter(cfg *config.ServerConfig) {
|
||||
func SetSizeLimit(cfg *config.ServerConfig) {
|
||||
sizeLimiter := NewSizeLimiter(cfg.RateLimit.MaxEventSize)
|
||||
for _, kindSizeLimit := range cfg.RateLimit.KindSizeLimits {
|
||||
sizeLimiter.AddKindSizeLimit(kindSizeLimit.Kind, kindSizeLimit.MaxSize)
|
||||
}
|
||||
|
||||
SetSizeLimit(sizeLimiter)
|
||||
SizeLimit(sizeLimiter)
|
||||
}
|
||||
|
||||
func NewSizeLimiter(globalMaxSize int) *SizeLimiter {
|
||||
@ -35,7 +35,7 @@ func GetSizeLimiter() *SizeLimiter {
|
||||
return sizeLimiterInstance
|
||||
}
|
||||
|
||||
func SetSizeLimit(sl *SizeLimiter) {
|
||||
func SizeLimit(sl *SizeLimiter) {
|
||||
sizeOnce.Do(func() {
|
||||
sizeLimiterInstance = sl
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user