Documentation
¶
Overview ¶
Package quota tracks per-user storage usage and enforces the users.quota_bytes ceiling at upload time.
quota_bytes == 0 means "unlimited". usage_bytes is incremented atomically in the DB on successful uploads and decremented on deletes; a periodic Recompute() job rebuilds it from authoritative node sizes.
Index ¶
- Variables
- type Service
- func (s *Service) AddUsage(ctx context.Context, userID int64, bytes int64) error
- func (s *Service) CheckCanWrite(ctx context.Context, userID int64, addBytes int64) error
- func (s *Service) Get(ctx context.Context, userID int64) (Snapshot, error)
- func (s *Service) Recompute(ctx context.Context, userID int64) (int64, error)
- func (s *Service) SetQuota(ctx context.Context, userID int64, bytes int64) error
- func (s *Service) SubUsage(ctx context.Context, userID int64, bytes int64) error
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
var ErrQuotaExceeded = errors.New("quota: exceeded")
ErrQuotaExceeded is returned by CheckCanWrite when the user is out of room.
var ErrUserNotFound = errors.New("quota: user not found")
ErrUserNotFound means the id doesn't name a user.
usage_bytes and quota_bytes are COALESCE'd columns on `users`, so a user that exists always reads back (0, 0) = "unlimited, nothing used". A no-rows result therefore says nothing about quotas — it says there is no such user, and the caller should answer 404 rather than leak `sql: no rows in result set` as a 500 (olivov H5, 2026-08-05).
Functions ¶
This section is empty.
Types ¶
type Service ¶
Service is the quota façade exposed to the rest of the codebase.
func (*Service) CheckCanWrite ¶
CheckCanWrite returns ErrQuotaExceeded when (used + addBytes) > quota. quota == 0 (unlimited) and userID <= 0 (anonymous / system) always pass.
func (*Service) Get ¶
Get returns the current snapshot. Returns ErrUserNotFound for an id that isn't a user.
func (*Service) Recompute ¶
Recompute rebuilds usage_bytes from the SUM(size) of nodes owned by the user. Returns ErrUserNotFound for an id that isn't a user — the underlying UPDATE would otherwise touch no rows and report success.