// At every interval, check the map for limiters that haven't been seen for
// more than the expiry duration and delete the entries.
At every interval, check the map for limiters that haven't been seen for
more than the expiry duration and delete the entries.
// At every interval check the map for limiters that haven ' t been seen for // more than the expiry duration and delete the entries .
func (r *rateLimiter) cleanup(interval time.Duration) func() {
	done := make(chan struct{})
	stop := func() {
		close(done)
	}
	ticker := time.NewTicker(interval)
	ttl := r.expirationTTL.Nanoseconds()
	go func() {
		defer ticker.Stop()
		for {
			select {
			case <-done:
				return
			case <-ticker.C:
				now := time.Now().UnixNano()
				r.Lock()
				for ip, v := range r.limiters {
					if now-v.lastSeen > ttl {
						delete(r.limiters, ip)
					}
				}
				r.Unlock()
			}
		}
	}()
	return stop
}
func ( r * rateLimiter ) cleanup ( interval time . Duration ) func ( ) { done := make ( chan struct { } ) stop := func ( ) { close ( done ) } ticker := time . NewTicker ( interval ) ttl := r . expirationTTL . Nanoseconds ( ) go func ( ) { defer ticker . Stop ( ) for { select { case <- done : return case <- ticker . C : now := time . Now ( ) . UnixNano ( ) r . Lock ( ) for ip , v := range r . limiters { if now - v . lastSeen > ttl { delete ( r . limiters , ip ) } } r . Unlock ( ) } } } ( ) return stop }
At every interval, check the map for limiters that haven't been seen for
more than the expiry duration and delete the entries.
At every interval check the map for limiters that haven ' t been seen for more than the expiry duration and delete the entries .