usage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentDate

func CurrentDate() string

CurrentDate returns today's date as a string in YYYY-MM-DD format.

Types

type LiveUsageTracker

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

LiveUsageTracker is the real implementation backed by the billing store.

func NewUsageTracker

func NewUsageTracker(store *Store) *LiveUsageTracker

func (*LiveUsageTracker) RecordAndCheck

func (t *LiveUsageTracker) RecordAndCheck(ctx context.Context, userID, agentID, domain, direction string) (bool, error)

type NoopUsageTracker

type NoopUsageTracker struct{}

NoopUsageTracker always allows everything. Used when billing is disabled.

func NewNoopUsageTracker

func NewNoopUsageTracker() *NoopUsageTracker

func (*NoopUsageTracker) RecordAndCheck

func (t *NoopUsageTracker) RecordAndCheck(ctx context.Context, userID, agentID, domain, direction string) (bool, error)

type Store

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

func NewStore

func NewStore(pool *pgxpool.Pool) *Store

func (*Store) CountAgentsByUser

func (s *Store) CountAgentsByUser(ctx context.Context, userID string) (int, error)

func (*Store) GetUsageSummary

func (s *Store) GetUsageSummary(ctx context.Context, userID, bucketDate string) (*UsageSummary, error)

func (*Store) IncrementUsageSummary

func (s *Store) IncrementUsageSummary(ctx context.Context, userID, bucketDate, direction string) error

func (*Store) RecordUsageEvent

func (s *Store) RecordUsageEvent(ctx context.Context, event *UsageEvent) error

type UsageEvent

type UsageEvent struct {
	ID        string    `json:"id"`
	UserID    string    `json:"user_id"`
	AgentID   string    `json:"agent_id"`
	Domain    string    `json:"domain"`
	Direction string    `json:"direction"`
	EventType string    `json:"event_type"`
	CreatedAt time.Time `json:"created_at"`
}

type UsageSummary

type UsageSummary struct {
	UserID        string `json:"user_id"`
	BucketDate    string `json:"bucket_date"`
	InboundCount  int    `json:"inbound_count"`
	OutboundCount int    `json:"outbound_count"`
	TotalCount    int    `json:"total_count"`
}

type UsageTracker

type UsageTracker interface {
	// RecordAndCheck records a usage event. Always returns true.
	RecordAndCheck(ctx context.Context, userID, agentID, domain, direction string) (allowed bool, err error)
}

UsageTracker records usage events. Always allows the action (no quota enforcement).

Jump to

Keyboard shortcuts

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