budget

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package budget provides durable fail-closed fixed-window accounting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter persists every admitted operation before returning success. A corrupt or unwritable counter fails closed instead of granting a fresh process-local allowance.

func Open

func Open(dir, name string, limit int, window time.Duration) (*Counter, error)

Open loads a durable counter from an owner-only state directory.

func (*Counter) Close

func (c *Counter) Close() error

Close releases the held state-directory descriptor.

func (*Counter) Take

func (c *Counter) Take(now time.Time) (bool, error)

Take durably charges one operation. Clock rollback preserves the existing window until wall time catches up, preventing restart or time manipulation from replenishing the allowance.

Jump to

Keyboard shortcuts

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