quota

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 0 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 quota holds the pure limit arithmetic for team and project resource quotas. It never touches storage, so enforcement stays testable.

Index

Constants

View Source
const (
	ScopeTeam    = "team"
	ScopeProject = "project"
)

Scope names the kind of owner a quota applies to.

View Source
const (
	ResourceApps      = "apps"
	ResourceDatabases = "databases"
	ResourceMemory    = "memory"
	ResourceCPU       = "cpu"
	ResourcePreviews  = "previews"
)

Resource names one limited dimension.

Variables

Resources lists every dimension in display order.

Functions

func Percent

func Percent(used, limit int64) int

Percent returns used as a whole percentage of limit, or -1 when unlimited.

Types

type Amounts

type Amounts struct {
	Apps        int64
	Databases   int64
	MemoryBytes int64
	NanoCPUs    int64
	Previews    int64
}

Amounts holds one number per dimension. For limits, 0 means unlimited. Memory is in bytes and CPU in nano-CPUs, the units services already store.

func Merge

func Merge(explicit, defaults Amounts) Amounts

Merge returns explicit limits with any unset (zero) dimension filled from defaults, so env-driven defaults apply wherever nobody chose a value.

func (Amounts) Get

func (a Amounts) Get(resource string) int64

Get returns the amount for a named dimension.

func (Amounts) Unlimited

func (a Amounts) Unlimited() bool

Unlimited reports whether no dimension is capped.

type Violation

type Violation struct {
	Resource  string
	Limit     int64
	Used      int64
	Requested int64
}

Violation is one dimension that a request would push past its limit.

func Check

func Check(limits, used, requested Amounts) []Violation

Check returns every dimension where used+requested exceeds a nonzero limit. Landing exactly on the limit is allowed. A request of zero never violates, so shrinking a resource that is already over limit still works.

Jump to

Keyboard shortcuts

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