Documentation
¶
Index ¶
- Constants
- type CreatedEvent
- type EndCurrentUsagePeriodParams
- type ExpirationPeriod
- type ExpirationPeriodDuration
- type Grant
- func (g Grant) ActiveAt(t time.Time) bool
- func (g Grant) GetExpiration() time.Time
- func (g Grant) GetNamespacedID() models.NamespacedID
- func (g Grant) GetNamespacedOwner() NamespacedOwner
- func (g Grant) RecurrenceBalance(currentBalance float64) float64
- func (g Grant) RolloverBalance(currentBalance float64) float64
- type ListParams
- type NamespacedOwner
- type OrderBy
- type Owner
- type OwnerConnector
- type OwnerMeter
- type OwnerNotFoundError
- type Repo
- type RepoCreateInput
- type VoidedEvent
Constants ¶
View Source
const (
EventSubsystem metadata.EventSubsystem = "credit"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreatedEvent ¶
type CreatedEvent grantEvent
func (CreatedEvent) EventMetadata ¶
func (e CreatedEvent) EventMetadata() metadata.EventMetadata
func (CreatedEvent) EventName ¶
func (e CreatedEvent) EventName() string
func (CreatedEvent) Validate ¶
func (e CreatedEvent) Validate() error
type ExpirationPeriod ¶
type ExpirationPeriod struct { // Count The expiration period count like 12 months. Count uint8 `json:"count,omitempty"` // Duration The expiration period duration like month. Duration ExpirationPeriodDuration `json:"duration,omitempty"` }
ExpirationPeriod of a credit grant.
func (ExpirationPeriod) GetExpiration ¶
func (c ExpirationPeriod) GetExpiration(t time.Time) time.Time
type ExpirationPeriodDuration ¶
type ExpirationPeriodDuration string
const ( ExpirationPeriodDurationHour ExpirationPeriodDuration = "HOUR" ExpirationPeriodDurationDay ExpirationPeriodDuration = "DAY" ExpirationPeriodDurationWeek ExpirationPeriodDuration = "WEEK" ExpirationPeriodDurationMonth ExpirationPeriodDuration = "MONTH" ExpirationPeriodDurationYear ExpirationPeriodDuration = "YEAR" )
Defines values for ExpirationPeriodDuration.
func (ExpirationPeriodDuration) Values ¶
func (ExpirationPeriodDuration) Values() (kinds []string)
type Grant ¶
type Grant struct { models.ManagedModel models.NamespacedModel // ID is the readonly identifies of a grant. ID string `json:"id,omitempty"` // Generic Owner reference OwnerID Owner `json:"owner"` // Amount The amount to grant. Must be positive. Amount float64 `json:"amount"` // Priority is a positive decimal numbers. With lower numbers indicating higher importance; // for example, a priority of 1 is more urgent than a priority of 2. // When there are several credit grants available for a single invoice, the system selects the credit with the highest priority. // In cases where credit grants share the same priority level, the grant closest to its expiration will be used first. // In the case of two credits have identical priorities and expiration dates, the system will use the credit that was created first. Priority uint8 `json:"priority"` // EffectiveAt The effective date. EffectiveAt time.Time `json:"effectiveAt"` // Expiration The expiration configuration. Expiration ExpirationPeriod `json:"expiration"` // ExpiresAt contains the exact expiration date calculated from effectiveAt and Expiration for rendering. // ExpiresAt is exclusive, meaning that the grant is no longer active after this time, but it is still active at the time. ExpiresAt time.Time `json:"expiresAt"` Metadata map[string]string `json:"metadata,omitempty"` // For user initiated voiding of the grant. VoidedAt *time.Time `json:"voidedAt,omitempty"` // How much of the grant can be rolled over after a reset operation. // Balance after a reset will be between ResetMinRollover and ResetMaxRollover. ResetMaxRollover float64 `json:"resetMaxRollover"` // How much balance the grant must have after a reset. // Balance after a reset will be between ResetMinRollover and ResetMaxRollover. ResetMinRollover float64 `json:"resetMinRollover"` // Recurrence config for the grant. If nil the grant doesn't recur. Recurrence *recurrence.Recurrence `json:"recurrence,omitempty"` }
Grant is an immutable definition used to increase balance.
func (Grant) GetExpiration ¶
Calculates expiration from effectiveAt and Expiration.
func (Grant) GetNamespacedID ¶
func (g Grant) GetNamespacedID() models.NamespacedID
func (Grant) GetNamespacedOwner ¶
func (g Grant) GetNamespacedOwner() NamespacedOwner
func (Grant) RecurrenceBalance ¶
Calculates the new balance after a recurrence from the current balance
func (Grant) RolloverBalance ¶
Calculates the new balance after a rollover from the current balance
type ListParams ¶
type NamespacedOwner ¶
func (NamespacedOwner) NamespacedID ¶
func (n NamespacedOwner) NamespacedID() models.NamespacedID
Casts the NamespacedGrantOwner to a NamespacedID. Owner might not be a valid ID.
type OwnerConnector ¶
type OwnerConnector interface { GetMeter(ctx context.Context, owner NamespacedOwner) (*OwnerMeter, error) GetStartOfMeasurement(ctx context.Context, owner NamespacedOwner) (time.Time, error) GetPeriodStartTimesBetween(ctx context.Context, owner NamespacedOwner, from, to time.Time) ([]time.Time, error) GetUsagePeriodStartAt(ctx context.Context, owner NamespacedOwner, at time.Time) (time.Time, error) GetOwnerSubjectKey(ctx context.Context, owner NamespacedOwner) (string, error) // FIXME: this is a terrible hack EndCurrentUsagePeriodTx(ctx context.Context, tx *entutils.TxDriver, owner NamespacedOwner, params EndCurrentUsagePeriodParams) error // FIXME: this is a terrible hack LockOwnerForTx(ctx context.Context, tx *entutils.TxDriver, owner NamespacedOwner) error }
type OwnerMeter ¶
type OwnerMeter struct { MeterSlug string DefaultParams *streaming.QueryParams WindowSize models.WindowSize SubjectKey string }
type OwnerNotFoundError ¶
type OwnerNotFoundError struct { Owner NamespacedOwner AttemptedOwner string }
func (OwnerNotFoundError) Error ¶
func (e OwnerNotFoundError) Error() string
type Repo ¶
type Repo interface { CreateGrant(ctx context.Context, grant RepoCreateInput) (*Grant, error) VoidGrant(ctx context.Context, grantID models.NamespacedID, at time.Time) error // For bw compatibility, if pagination is not provided we return a simple array ListGrants(ctx context.Context, params ListParams) (pagination.PagedResponse[Grant], error) // ListActiveGrantsBetween returns all grants that are active at any point between the given time range. ListActiveGrantsBetween(ctx context.Context, owner NamespacedOwner, from, to time.Time) ([]Grant, error) GetGrant(ctx context.Context, grantID models.NamespacedID) (Grant, error) entutils.TxCreator entutils.TxUser[Repo] }
type RepoCreateInput ¶
type RepoCreateInput struct { OwnerID Owner Namespace string Amount float64 Priority uint8 EffectiveAt time.Time Expiration ExpirationPeriod ExpiresAt time.Time Metadata map[string]string ResetMaxRollover float64 ResetMinRollover float64 Recurrence *recurrence.Recurrence }
type VoidedEvent ¶
type VoidedEvent grantEvent
func (VoidedEvent) EventMetadata ¶
func (e VoidedEvent) EventMetadata() metadata.EventMetadata
func (VoidedEvent) EventName ¶
func (e VoidedEvent) EventName() string
func (VoidedEvent) Validate ¶
func (e VoidedEvent) Validate() error
Click to show internal directories.
Click to hide internal directories.