gwbudget

package
v0.1.4607 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gwbudget is the gateway's budget point (P3 of docs/subsystems/plugin-runtime.md): what holds a gateway key to the limits its owner set (#585). The gateway asks it before a key's request goes to any provider; plugins/budget serves internal/budget's limiter while it is on.

It fails closed: a request of a key held to a limit is not sent while no limiter serves it (ErrUnlimited). A request without a key, or of a key with no limit, never asks it.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnlimited = errors.New("this gateway key is held to a limit, but magpie's Key limits built-in isn't serving it, so nothing was sent; turn it on in magpie's Plugins › Built-in")

ErrUnlimited is the error a key's request gets when the key is held to a limit and nothing can hold it.

Functions

func ForgetRefreshForTest

func ForgetRefreshForTest()

ForgetRefreshForTest lets the next Limiting refresh at once, as it would a second after the last one.

func Limit

func Limit(l Limiter) (remove func())

Limit serves l until remove. Registering one while another is served stacks: the last serves until it is removed.

func Refresh

func Refresh(f func()) (stop func())

Refresh sets what the gateway asks when a key held to a limit comes and no limiter is served: pluginrt's refresh, which turns the plugin on when a key has a limit. stop takes it away.

Types

type Limiter

type Limiter interface {
	Reserve(who access.Identity, body int64, model string, now time.Time) (release func(), refused Refusal)
}

Limiter lets a key's request in, holding what it is expected to use until release, or refuses it. body is the request's size in bytes (-1 unknown) and model the model it named.

func Limiting

func Limiting(who access.Identity) (Limiter, error)

Limiting is the limiter for who's request: nil, nil when who has no limit; ErrUnlimited when it has one and none serves. With none, one refresh is asked first (at most once a second, never from inside one), so a limit set a moment ago turns the plugin on for the request that needs it. Fail closed.

type Refusal

type Refusal interface {
	error
	// RetryAfter is how long until the limit resets, in whole seconds.
	RetryAfter(now time.Time) int
	// ResetAt is when it resets.
	ResetAt() time.Time
}

Refusal is why a key's request was turned away, as the client is told.

type Spender added in v0.1.3170

type Spender interface {
	Spent(who access.Identity, now time.Time) []access.SpentScope
}

Spender is a Limiter that can tell which of a key's limits of some models (access.Limit.Models) have nothing left: the gateway leaves their models out of the request's candidates (access.Identity.Spent).

Jump to

Keyboard shortcuts

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