usebudget

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package usebudget models finite and unlimited approval use budgets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limit

type Limit int

Limit is either a positive finite use count or Unlimited.

const Unlimited Limit = 0

Unlimited represents a grant that remains usable until its time limit.

func (Limit) Allows

func (l Limit) Allows(used, reserved int) bool

Allows reports whether used and reserved uses remain within the limit.

func (Limit) Exhausted

func (l Limit) Exhausted(used int) bool

Exhausted reports whether a finite limit has been consumed.

func (Limit) IsFinite

func (l Limit) IsFinite() bool

IsFinite reports whether the limit is a positive finite count.

func (Limit) IsUnlimited

func (l Limit) IsUnlimited() bool

IsUnlimited reports whether the limit has no use-count ceiling.

func (Limit) MarshalJSON

func (l Limit) MarshalJSON() ([]byte, error)

MarshalJSON represents unlimited budgets as JSON null.

func (Limit) Remaining

func (l Limit) Remaining(used, reserved int) (int, bool)

Remaining returns the finite remaining count and whether the limit is finite.

func (*Limit) UnmarshalJSON

func (l *Limit) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts JSON null or a positive integer.

type Optional

type Optional struct {
	Limit     Limit
	Specified bool
}

Optional preserves whether a request omitted its use limit, explicitly requested unlimited use, or requested a finite count.

func Finite

func Finite(value int) Optional

Finite returns an explicitly requested finite use limit.

func NoLimit

func NoLimit() Optional

NoLimit returns an explicitly requested unlimited use budget.

func (Optional) MarshalJSON

func (o Optional) MarshalJSON() ([]byte, error)

MarshalJSON delegates to the requested limit representation.

func (*Optional) UnmarshalJSON

func (o *Optional) UnmarshalJSON(data []byte) error

UnmarshalJSON marks the value as specified before decoding its limit.

Jump to

Keyboard shortcuts

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