mirror of
https://github.com/jeremyd/ergo.git
synced 2026-05-14 00:58:36 -07:00
remove more indirections
This commit is contained in:
@@ -150,17 +150,6 @@ func (ct *Throttler) BanMessage() string {
|
||||
return ct.banMessage
|
||||
}
|
||||
|
||||
// NewThrottler returns a new client connection throttler.
|
||||
// The throttler is functional, but disabled; it can be enabled via `ApplyConfig`.
|
||||
func NewThrottler() *Throttler {
|
||||
var ct Throttler
|
||||
|
||||
// initialize empty population; all other state is configurable
|
||||
ct.population = make(map[string]ThrottleDetails)
|
||||
|
||||
return &ct
|
||||
}
|
||||
|
||||
// ApplyConfig atomically applies a config update to a throttler
|
||||
func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
|
||||
// assemble exempted nets
|
||||
@@ -172,6 +161,10 @@ func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
|
||||
ct.Lock()
|
||||
defer ct.Unlock()
|
||||
|
||||
if ct.population == nil {
|
||||
ct.population = make(map[string]ThrottleDetails)
|
||||
}
|
||||
|
||||
ct.enabled = config.Enabled
|
||||
ct.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
|
||||
ct.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)
|
||||
|
||||
Reference in New Issue
Block a user