Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BalanceConnector ¶
type BalanceConnector interface {
// GetBalanceSinceSnapshot returns the result of the engine.Run since a given snapshot.
GetBalanceSinceSnapshot(ctx context.Context, ownerID models.NamespacedID, snap balance.Snapshot, at time.Time) (engine.RunResult, error)
// GetBalanceAt returns the result of the engine.Run at a given time.
// It tries to minimize execution cost by calculating from the latest valid snapshot, thus the length of the returned history WILL NOT be deterministic.
GetBalanceAt(ctx context.Context, ownerID models.NamespacedID, at time.Time) (engine.RunResult, error)
// GetBalanceForPeriod returns the result of the engine.Run for the provided period.
// The returned history will exactly match the provided period.
GetBalanceForPeriod(ctx context.Context, ownerID models.NamespacedID, period timeutil.Period) (engine.RunResult, error)
// ResetUsageForOwner resets the usage for an owner at a given time.
ResetUsageForOwner(ctx context.Context, ownerID models.NamespacedID, params ResetUsageForOwnerParams) (balanceAfterReset *balance.Snapshot, err error)
// GetLastValidSnapshotAt fetches the last valid snapshot for an owner.
GetLastValidSnapshotAt(ctx context.Context, owner models.NamespacedID, at time.Time) (balance.Snapshot, error)
}
Generic connector for balance related operations.
type CreateGrantInput ¶
type CreditConnector ¶
type CreditConnector interface {
BalanceConnector
GrantConnector
}
func NewCreditConnector ¶
func NewCreditConnector( cfg CreditConnectorConfig, ) CreditConnector
type CreditConnectorConfig ¶
type CreditConnectorConfig struct {
// services
GrantRepo grant.Repo
BalanceSnapshotService balance.SnapshotService
OwnerConnector grant.OwnerConnector
StreamingConnector streaming.Connector
Logger *slog.Logger
Tracer trace.Tracer
Publisher eventbus.Publisher
TransactionManager transaction.Creator
// configuration
Granularity time.Duration
SnapshotGracePeriod isodate.Period
}
type GrantConnector ¶
type GrantConnector interface {
CreateGrant(ctx context.Context, owner models.NamespacedID, grant CreateGrantInput) (*grant.Grant, error)
VoidGrant(ctx context.Context, grantID models.NamespacedID) error
}
type GrantNotFoundError ¶
type GrantNotFoundError struct {
GrantID string
}
func (*GrantNotFoundError) Error ¶
func (e *GrantNotFoundError) Error() string
Click to show internal directories.
Click to hide internal directories.