mirror of
https://github.com/go-i2p/go-limit.git
synced 2025-06-10 02:58:20 -04:00
18 lines
439 B
Go
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))
|
|
}
|
|
}
|