budget

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 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 budget is the domain layer for the Budget entity: a recurring spend cap in USD over a calendar period in UTC. Policies link budgets by id.

This package validates one row's shape, fills its defaults, and stores it. Out of scope: counting spend, refusing requests over a cap, and the pricing a capped model needs.

Index

Constants

View Source
const (
	DefaultPeriod = PeriodMonth
	DefaultMode   = ModeHard
)

Defaults for the fields a wire form may omit.

Variables

This section is empty.

Functions

This section is empty.

Types

type Budget

type Budget struct {
	Meta meta.Metadata `json:"metadata" yaml:"metadata"`
	Spec Spec          `json:"spec"     yaml:"spec"`
}

Budget is a named, recurring spend cap.

func (*Budget) Default

func (b *Budget) Default()

Default fills the fields a wire form may omit, so a stored row and the manifest that declared it converge instead of differing by an empty period or mode forever. Nil receiver is a no-op.

func (*Budget) Validate

func (b *Budget) Validate() error

Validate runs intra-row rules via the shared meta.Validator and requires an owner of kind system, organization, team, project or user; team and project owners carry an id, an organization owner none.

type Mode

type Mode string

Mode decides what reaching the cap does.

const (
	// ModeHard refuses requests once the cap is spent.
	ModeHard Mode = "hard"
	// ModeAlert reports the overrun and lets requests through.
	ModeAlert Mode = "alert"
)

type Period

type Period string

Period is the calendar period a budget's amount covers, in UTC.

const (
	PeriodDay   Period = "day"
	PeriodWeek  Period = "week"
	PeriodMonth Period = "month"
)

type Spec

type Spec struct {
	// AmountUSD is a decimal string with at most two fractional digits, so money never round-trips through a float.
	AmountUSD string `` /* 233-byte string literal not displayed */
	Period    Period `` /* 178-byte string literal not displayed */
	Mode      Mode   `` /* 254-byte string literal not displayed */
}

Spec carries the cap, its period and its mode.

type Store

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

Store is the Budget data-access type.

func NewStore

func NewStore(q *gen.Queries) *Store

NewStore constructs a Store from an existing sqlc Queries handle.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes a Budget by id; policies linking it lose the link.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*Budget, error)

Get returns the Budget with the given id, or (nil, nil) if not found.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*Budget, error)

List returns every Budget row.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, b *Budget) error

Upsert writes b. The caller sets Meta.ID.

Jump to

Keyboard shortcuts

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