exhausted

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package exhausted owns the unified joint limit-key store (0.1.1).

A stored key is a filter over candidate dimensions: a candidate combination matching every stored dimension is skipped until ResetsAt passes. Expired entries delete on read; Prune sweeps entries nobody reads anymore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKey

func BuildKey(s Segments) string

BuildKey assembles the canonical key: fixed dimension order, non-empty dimensions only. Prefixes keep dimensions unambiguous after the join.

func FullKey

func FullKey(plugin, provider, account, model, proxy string) string

FullKey builds the strictest key: every known dimension. Used when a rate/quota error carries no scope: only the exact combination is skipped, so the router bypasses through everything else.

func KeyFromScope

func KeyFromScope(plugin, provider, account, model, proxy string, scope []string) (string, error)

KeyFromScope builds the stored key for one error outcome: plugin and provider always participate, the scope words select the narrowing dimensions. Unknown scope words fail closed so typos never silently drop the marking.

func SubKeys

func SubKeys(full Segments) []string

SubKeys returns every stored-key shape matching the full candidate: plugin and provider fixed, every non-empty subset of the narrowing dimensions present on the candidate, most-specific first.

Types

type Segments

type Segments struct {
	Plugin   string
	Provider string
	Account  string
	Model    string
	Proxy    string
}

Segments is the full identity of one request attempt. Plugin and Provider always participate; Account, Model and Proxy narrow the key when non-empty.

type Service

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

Service persists ExhaustedEntry rows keyed by the canonical key.

func New

func New(database *db.DB) *Service

New constructs the exhausted Service.

func (*Service) Limited

func (s *Service) Limited(key string) (bool, error)

Limited reports whether the exact key limits now. Expired entries delete on read, so a passed limit never blocks again.

func (*Service) LimitedAny

func (s *Service) LimitedAny(full Segments) (string, error)

LimitedAny reports the first matching stored key for the full candidate, most-specific first. Empty when nothing limits the candidate.

func (*Service) Mark

func (s *Service) Mark(key string, resetsAt time.Time, reason string) error

Mark records the key as limited until resetsAt, overwriting any entry.

func (*Service) Prune

func (s *Service) Prune() (int, error)

Prune deletes expired entries and returns the removed count.

Jump to

Keyboard shortcuts

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