refactor limit functions

This commit is contained in:
0ceanSlim 2024-09-05 11:09:03 -04:00
parent da46e23ae0
commit b22fbe6aa8
3 changed files with 6 additions and 6 deletions

View File

@ -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,

View File

@ -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
})

View File

@ -46,8 +46,8 @@ func main() {
log.Fatal("Error initializing database: ", err)
}
config.SetupRateLimiter(cfg)
config.SetupSizeLimiter(cfg)
config.SetRateLimit(cfg)
config.SetSizeLimit(cfg)
config.ClearTemporaryBans()