quota

package
v0.0.0-...-15beef2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-3-Clause Imports: 3 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotEnoughReserved       = errors.New("Not enough reserved items")
	ErrLimitLowerThanAllocated = errors.New("New limit is less than the current allocated value")
	ErrLessThanZero            = errors.New("Invalid value, cannot be less than 0")
	ErrQuotaNotFound           = errors.New("quota not found")
)
View Source
var UnlimitedQuota = Quota{Limit: -1, InUse: 0}

UnlimitedQuota is the struct which any new unlimited quota copies from.

Functions

This section is empty.

Types

type MockQuotaService

type MockQuotaService struct {
	OnInc      func(QuotaItem, int) error
	OnSet      func(QuotaItem, int) error
	OnSetLimit func(QuotaItem, int) error
	OnGet      func(QuotaItem) (*Quota, error)
}

func (*MockQuotaService) Get

func (m *MockQuotaService) Get(ctx context.Context, item QuotaItem) (*Quota, error)

func (*MockQuotaService) Inc

func (m *MockQuotaService) Inc(ctx context.Context, item QuotaItem, delta int) error

func (*MockQuotaService) Set

func (m *MockQuotaService) Set(ctx context.Context, item QuotaItem, quantity int) error

func (*MockQuotaService) SetLimit

func (m *MockQuotaService) SetLimit(ctx context.Context, item QuotaItem, limit int) error

type MockQuotaStorage

type MockQuotaStorage struct {
	OnSet      func(string, int) error
	OnSetLimit func(string, int) error
	OnGet      func(string) (*Quota, error)
}

func (*MockQuotaStorage) Get

func (m *MockQuotaStorage) Get(ctx context.Context, name string) (*Quota, error)

func (*MockQuotaStorage) Set

func (m *MockQuotaStorage) Set(ctx context.Context, name string, limit int) error

func (*MockQuotaStorage) SetLimit

func (m *MockQuotaStorage) SetLimit(ctx context.Context, name string, limit int) error

type Quota

type Quota struct {
	Limit int `json:"limit"`
	InUse int `json:"inuse"`
}

func (*Quota) IsUnlimited

func (q *Quota) IsUnlimited() bool

type QuotaExceededError

type QuotaExceededError struct {
	Requested uint
	Available uint
}

func (*QuotaExceededError) Error

func (err *QuotaExceededError) Error() string

type QuotaItem

type QuotaItem interface {
	GetName() string
}

type QuotaItemInUse

type QuotaItemInUse interface {
	QuotaItem
	GetQuotaInUse() (int, error)
}

type QuotaService

type QuotaService interface {
	Inc(ctx context.Context, item QuotaItem, delta int) error
	Set(ctx context.Context, item QuotaItem, quantity int) error
	SetLimit(ctx context.Context, item QuotaItem, limit int) error
	Get(ctx context.Context, item QuotaItem) (*Quota, error)
}

type QuotaStorage

type QuotaStorage interface {
	SetLimit(ctx context.Context, name string, limit int) error
	Get(ctx context.Context, name string) (*Quota, error)
	Set(ctx context.Context, name string, quantity int) error
}

Jump to

Keyboard shortcuts

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