Files
go-limit/options.go
2025-02-01 14:36:31 -05:00

18 lines
439 B
Go

package limitedlistener
import "golang.org/x/time/rate"
// WithMaxConnections sets the maximum number of concurrent connections
func WithMaxConnections(max int) Option {
return func(l *LimitedListener) {
l.maxConns = max
}
}
// WithRateLimit sets connections per second limit
func WithRateLimit(perSecond float64) Option {
return func(l *LimitedListener) {
l.limiter = rate.NewLimiter(rate.Limit(perSecond), int(perSecond))
}
}