ratelimit

package
v0.0.14 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled     bool
	DefaultRule Rule
	// Rules allows per-path custom rate limit rules keyed by request path
	// e.g., "/api/auth/signin": {Window: time.Minute, Max: 20}
	Rules map[string]Rule
}

Config for the rate limiting service

type Rule

type Rule struct {
	Window time.Duration `json:"window"`
	Max    int           `json:"max"`
}

Rule defines a rate limit window and maximum allowed requests

type Service

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

Service provides rate limit checks

func NewService

func NewService(storage Storage, cfg Config) *Service

NewService constructs a rate limit service

func (*Service) CheckLimit

func (s *Service) CheckLimit(ctx context.Context, key string, rule Rule) (bool, error)

CheckLimit returns true if within limit; false if exceeded

func (*Service) CheckLimitForPath

func (s *Service) CheckLimitForPath(ctx context.Context, key, path string) (bool, error)

CheckLimitForPath uses a configured per-path rule if present, otherwise DefaultRule

type Storage

type Storage interface {
	// Increment increases the counter for key within the window and returns the current count
	Increment(ctx context.Context, key string, window time.Duration) (int, error)
}

Storage abstracts the rate limit counter storage

Jump to

Keyboard shortcuts

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