slidingcounter

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package slidingcounter implements the Sliding Window Counter rate limiting algorithm.

It calculates an estimated request volume using a weighted moving average of the current and previous window counters, providing high precision with strictly O(1) memory footprint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Strategy

type Strategy struct{}

Strategy implements the algorithm.Algorithm interface for Sliding Window Counter.

func New

func New() *Strategy

New creates a new instance of the Sliding Window Counter algorithm strategy.

func (*Strategy) EvaluateMemory

func (s *Strategy) EvaluateMemory(now time.Time, state *algorithm.State, limit int64, window time.Duration) algorithm.Result

EvaluateMemory evaluates the sliding window counter rate limit state synchronously in RAM.

func (*Strategy) Name

func (s *Strategy) Name() string

Name returns the unique identifier of the algorithm strategy.

func (*Strategy) RedisScript

func (s *Strategy) RedisScript() string

RedisScript returns the high-performance atomic Lua script for Redis execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL