ratelimit

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ratelimit provides a sliding-window start limiter — the windowed timestamp pattern from internal/action/auto.go:reserve(), reusable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window allows up to max events per sliding window. max <= 0 is unlimited. Safe for concurrent use; clock injectable for tests.

func New

func New(maxEvents int, window time.Duration) *Window

New returns a Window allowing maxEvents per window.

func (*Window) Allow

func (w *Window) Allow() bool

Allow reports whether an event fits the budget, recording it if so.

func (*Window) Count

func (w *Window) Count() int

Count returns the number of events currently in the window (peek; no record).

func (*Window) Window

func (w *Window) Window() time.Duration

Window returns the configured sliding-window duration.

Jump to

Keyboard shortcuts

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