ratelimit

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ratelimit limits how often each client can call a Tern app:

ternApp(kit.WithPlugins(ratelimit.New(ratelimit.Rate(10, time.Minute))))

Each client gets a token bucket: up to Burst requests at once, refilled at the given rate. By default only state-changing requests (POST, PUT, PATCH, DELETE), such as form actions and API writes, are limited. A client over the limit gets 429 Too Many Requests with Retry-After.

Clients are identified by their IP address from kit.ClientIP. Behind a reverse proxy, configure the app with kit.WithTrustedProxies.

Since v1.16 kit limits state-changing requests without the plugin, to 120 a minute in bursts of 60 (ADR 0027); adding the plugin replaces that limit with its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Plugin)

Option configures the plugin.

func Burst

func Burst(n int) Option

Burst sets how many requests a client may make at once. It defaults to n from Rate.

func KeyFunc

func KeyFunc(fn func(*http.Request) string) Option

KeyFunc identifies the client for a request. The default is kit.ClientIP. Return "" to exempt a request.

func Methods

func Methods(m ...string) Option

Methods sets which methods are limited. Pass none to limit every request.

func Rate

func Rate(n int, per time.Duration) Option

Rate allows n requests per period, per client. The default is 30 per minute.

type Plugin

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

Plugin limits request rates. Create it with New.

func New

func New(opts ...Option) *Plugin

New returns the rate limiting plugin.

func (*Plugin) Name

func (*Plugin) Name() string

Name implements kit.Plugin.

func (*Plugin) Setup

func (p *Plugin) Setup(s *kit.Setup) error

Setup implements kit.Plugin.

Jump to

Keyboard shortcuts

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