spendlimit

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 2 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 spendlimit names the monetary limit subjects, periods and refusal reasons, and computes the UTC calendar windows they reset on. It is a leaf package so the throttle, the router and the HTTP layer agree on one contract.

Index

Constants

View Source
const (
	SubjectKey  = "key"  // api key name
	SubjectUser = "user" // router.UserID: attributes["user_id"] or svc:<key_name>
	SubjectTeam = "team" // team id
)

Subject types a limit can apply to.

View Source
const (
	PeriodDay   = "day"
	PeriodMonth = "month"
)

Periods are UTC calendar windows.

View Source
const ReasonUnavailable = "spend_unavailable"

ReasonUnavailable is reported when the counters cannot be read and SPEND_LIMITS_FAIL_MODE=closed.

View Source
const Wildcard = "*"

Wildcard as a subject id is the default limit for every subject of a type.

Variables

Enforced lists the (subject, period) pairs checked on every call, in the order a refusal names them.

Functions

func IsReason

func IsReason(kind string) bool

IsReason reports a refusal caused by an exhausted spend limit.

func Reason

func Reason(subject, period string) string

Reason is the throttle kind for a tripped limit, e.g. "spend_key_daily".

func RetryAfter

func RetryAfter(kind string, now time.Time) (d time.Duration, ok bool)

RetryAfter is the time until the period behind a spend refusal resets, rounded up to whole seconds. ok is false for any other kind.

func ValidPeriod

func ValidPeriod(p string) bool

ValidPeriod reports a known period.

func ValidSubject

func ValidSubject(s string) bool

ValidSubject reports a subject type that is enforced.

func Window

func Window(period string, now time.Time) (id string, end time.Time)

Window returns the id of the period containing now and the instant it ends.

Types

This section is empty.

Jump to

Keyboard shortcuts

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