Documentation
¶
Index ¶
- func NewLedgerAlreadyExistsProblem(ctx context.Context, err error, existingEntry Ledger) models.Problem
- type Balance
- type Connector
- type EntryType
- type ExpirationPeriod
- type ExpirationPeriodDuration
- type Feature
- type FeatureBalance
- type FeatureID
- type FeatureInvalidFiltersError
- type FeatureNotFoundError
- type FeatureOrderBy
- type FeatureWithNameAlreadyExistsError
- type Grant
- type GrantBalance
- type GrantID
- type GrantNotFoundError
- type GrantRollover
- type GrantRolloverType
- type GrantType
- type HighWatermarBeforeError
- type HighWatermark
- type Ledger
- type LedgerAlreadyExistsError
- type LedgerAlreadyExistsProblemResponse
- type LedgerEntry
- type LedgerEntryList
- func (c *LedgerEntryList) AddGrant(grant Grant)
- func (c *LedgerEntryList) AddGrantUsage(grantBalance GrantBalance, from time.Time, to time.Time, amount float64)
- func (c *LedgerEntryList) AddReset(reset Reset)
- func (c *LedgerEntryList) AddVoidGrant(grant Grant)
- func (c *LedgerEntryList) Append(other LedgerEntryList)
- func (f LedgerEntryList) GetEntries() []LedgerEntry
- func (f LedgerEntryList) Len() int
- func (f LedgerEntryList) MarshalJSON() ([]byte, error)
- func (f LedgerEntryList) Skip(n int) LedgerEntryList
- func (f LedgerEntryList) Truncate(limit int) LedgerEntryList
- type LedgerEntryType
- type LedgerID
- type LedgerNotFoundError
- type LedgerOrderBy
- type ListFeaturesParams
- type ListGrantsParams
- type ListLedgersParams
- type LockErrNotObtainedError
- type NamespacedFeatureID
- type NamespacedGrantID
- type NamespacedLedgerID
- type Pagination
- type Period
- type Reset
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Balance ¶
type Balance struct {
LedgerID LedgerID `json:"id"`
Metadata map[string]string `json:"metadata,omitempty"`
Subject string `json:"subject"`
FeatureBalances []FeatureBalance `json:"featureBalances"`
GrantBalances []GrantBalance `json:"grantBalances"`
}
Balance of a subject in a credit.
type Connector ¶
type Connector interface {
// Ledger
CreateLedger(ctx context.Context, ledger Ledger) (Ledger, error)
ListLedgers(ctx context.Context, params ListLedgersParams) ([]Ledger, error)
// Grant
CreateGrant(ctx context.Context, grant Grant) (Grant, error)
VoidGrant(ctx context.Context, grant Grant) (Grant, error)
ListGrants(ctx context.Context, params ListGrantsParams) ([]Grant, error)
GetGrant(ctx context.Context, grantID NamespacedGrantID) (Grant, error)
// Credit
GetBalance(ctx context.Context, ledgerID NamespacedLedgerID, cutline time.Time) (Balance, error)
GetHistory(ctx context.Context, ledgerID NamespacedLedgerID, from time.Time, to time.Time, pagination Pagination) (LedgerEntryList, error)
GetHighWatermark(ctx context.Context, ledgerID NamespacedLedgerID) (HighWatermark, error)
Reset(ctx context.Context, reset Reset) (Reset, []Grant, error)
// Feature
CreateFeature(ctx context.Context, feature Feature) (Feature, error)
DeleteFeature(ctx context.Context, featureID NamespacedFeatureID) error
ListFeatures(ctx context.Context, params ListFeaturesParams) ([]Feature, error)
GetFeature(ctx context.Context, featureID NamespacedFeatureID) (Feature, error)
}
type EntryType ¶
type EntryType string
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 Feature ¶
type Feature struct {
Namespace string `json:"-"`
ID *FeatureID `json:"id,omitempty"`
// Name The name of the feature.
Name string `json:"name"`
// MeterSlug The meter that the feature is associated with and decreases grants by usage.
MeterSlug string `json:"meterSlug,omitempty"`
// MeterGroupByFilters Optional meter group by filters. Useful if the meter scope is broader than what feature tracks.
MeterGroupByFilters *map[string]string `json:"meterGroupByFilters,omitempty"`
// Read-only fields
Archived *bool `json:"archived,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
}
Feature is a feature or service offered to a customer. For example: CPU-Hours, Tokens, API Calls, etc.
type FeatureBalance ¶
type FeatureInvalidFiltersError ¶
type FeatureInvalidFiltersError struct {
RequestedFilters map[string]string
MeterGroupByColumns []string
}
func (*FeatureInvalidFiltersError) Error ¶
func (e *FeatureInvalidFiltersError) Error() string
type FeatureNotFoundError ¶
type FeatureNotFoundError struct {
ID FeatureID
}
func (*FeatureNotFoundError) Error ¶
func (e *FeatureNotFoundError) Error() string
type FeatureOrderBy ¶
type FeatureOrderBy string
const ( FeatureOrderByCreatedAt FeatureOrderBy = "created_at" FeatureOrderByUpdatedAt FeatureOrderBy = "updated_at" FeatureOrderByID FeatureOrderBy = "id" )
type FeatureWithNameAlreadyExistsError ¶
func (*FeatureWithNameAlreadyExistsError) Error ¶
func (e *FeatureWithNameAlreadyExistsError) Error() string
type Grant ¶
type Grant struct {
Namespace string `json:"-"`
// ID is the readonly identifies of a grant.
ID *GrantID `json:"id,omitempty"`
// Parent ID is the readonly identifies of the grant's parent if any.
ParentID *GrantID `json:"parentID,omitempty"`
// Subject The subject to grant the amount to.
LedgerID LedgerID `json:"ledgerID"`
// Type The grant type.
Type GrantType `json:"type"`
// FeatureID The feature ID.
FeatureID *FeatureID `json:"featureID"`
// Amount The amount to grant. Can be positive or negative number.
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 time.Time `json:"expiresAt"`
Metadata map[string]string `json:"metadata,omitempty"`
// Rollover Grant rollover configuration.
Rollover *GrantRollover `json:"rollover,omitempty"`
// Void The voided date.
Void bool `json:"void"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
}
Grant is used to increase balance of specific subjects.
func (Grant) ExpirationDate ¶
type GrantBalance ¶
type GrantNotFoundError ¶
type GrantNotFoundError struct {
GrantID GrantID
}
func (*GrantNotFoundError) Error ¶
func (e *GrantNotFoundError) Error() string
type GrantRollover ¶
type GrantRollover struct {
// MaxAmount Maximum amount to rollover.
MaxAmount *float64 `json:"maxAmount,omitempty"`
// Type The rollover type to use:
Type GrantRolloverType `json:"type"`
}
GrantRollover configuration.
type GrantRolloverType ¶
type GrantRolloverType string
const ( GrantRolloverTypeOriginalAmount GrantRolloverType = "ORIGINAL_AMOUNT" GrantRolloverTypeRemainingAmount GrantRolloverType = "REMAINING_AMOUNT" )
Defines values for GrantRolloverType.
func (GrantRolloverType) Values ¶
func (GrantRolloverType) Values() (kinds []string)
type GrantType ¶
type GrantType string
const (
GrantTypeUsage GrantType = "USAGE"
)
Defines values for GrantType.
type HighWatermarBeforeError ¶
HighWatermarBeforeError is returned when a lock cannot be obtained.
func (*HighWatermarBeforeError) Error ¶
func (e *HighWatermarBeforeError) Error() string
type HighWatermark ¶
type Ledger ¶
type Ledger struct {
Namespace string `json:"-"`
// ID is the ID of the ledger instance
ID LedgerID `json:"id,omitempty"`
// Subject specifies which metering subject this ledger is referring to
Subject string `json:"subject"`
Metadata map[string]string `json:"metadata,omitempty"`
// CreatedAt is the time the ledger was created
CreatedAt time.Time `json:"createdAt"`
}
type LedgerAlreadyExistsError ¶
type LedgerAlreadyExistsError struct {
Ledger Ledger
}
func (*LedgerAlreadyExistsError) Error ¶
func (e *LedgerAlreadyExistsError) Error() string
type LedgerAlreadyExistsProblemResponse ¶
type LedgerAlreadyExistsProblemResponse struct {
*models.StatusProblem
ConflictingEntity Ledger `json:"conflictingEntity"`
}
func (*LedgerAlreadyExistsProblemResponse) Respond ¶
func (p *LedgerAlreadyExistsProblemResponse) Respond(w http.ResponseWriter)
type LedgerEntry ¶
type LedgerEntry struct {
ID *GrantID `json:"id,omitempty"`
Type LedgerEntryType `json:"type"`
Time time.Time `json:"time"`
FeatureID *FeatureID `json:"featureId,omitempty"`
Amount *float64 `json:"amount,omitempty"`
Period *Period `json:"period,omitempty"`
}
LedgerEntry is a credit ledger entry.
type LedgerEntryList ¶
type LedgerEntryList struct {
// contains filtered or unexported fields
}
func NewLedgerEntryList ¶
func NewLedgerEntryList() LedgerEntryList
func (*LedgerEntryList) AddGrant ¶
func (c *LedgerEntryList) AddGrant(grant Grant)
func (*LedgerEntryList) AddGrantUsage ¶
func (c *LedgerEntryList) AddGrantUsage(grantBalance GrantBalance, from time.Time, to time.Time, amount float64)
func (*LedgerEntryList) AddReset ¶
func (c *LedgerEntryList) AddReset(reset Reset)
func (*LedgerEntryList) AddVoidGrant ¶
func (c *LedgerEntryList) AddVoidGrant(grant Grant)
func (*LedgerEntryList) Append ¶
func (c *LedgerEntryList) Append(other LedgerEntryList)
func (LedgerEntryList) GetEntries ¶
func (f LedgerEntryList) GetEntries() []LedgerEntry
func (LedgerEntryList) Len ¶
func (f LedgerEntryList) Len() int
func (LedgerEntryList) MarshalJSON ¶
func (f LedgerEntryList) MarshalJSON() ([]byte, error)
func (LedgerEntryList) Skip ¶
func (f LedgerEntryList) Skip(n int) LedgerEntryList
Skip removes the first n entries.
func (LedgerEntryList) Truncate ¶
func (f LedgerEntryList) Truncate(limit int) LedgerEntryList
Truncate removes all entries after the limit.
type LedgerEntryType ¶
type LedgerEntryType string
const ( LedgerEntryTypeGrant LedgerEntryType = "GRANT" LedgerEntryTypeVoid LedgerEntryType = "VOID" LedgerEntryTypeReset LedgerEntryType = "RESET" LedgerEntryTypeGrantUsage LedgerEntryType = "GRANT_USAGE" )
Defines values for LedgerEntryType.
func (LedgerEntryType) Values ¶
func (LedgerEntryType) Values() (kinds []string)
type LedgerNotFoundError ¶
type LedgerNotFoundError struct {
LedgerID LedgerID
}
func (*LedgerNotFoundError) Error ¶
func (e *LedgerNotFoundError) Error() string
type LedgerOrderBy ¶
type LedgerOrderBy string
const ( LedgerOrderByCreatedAt LedgerOrderBy = "created_at" LedgerOrderBySubject LedgerOrderBy = "subject" LedgerOrderByID LedgerOrderBy = "id" )
type ListFeaturesParams ¶
type ListFeaturesParams struct {
Namespace string
IncludeArchived bool
Offset int
Limit int
OrderBy FeatureOrderBy
}
type ListGrantsParams ¶
type ListLedgersParams ¶
type LockErrNotObtainedError ¶
LockErrNotObtainedError is returned when a lock cannot be obtained.
func (*LockErrNotObtainedError) Error ¶
func (e *LockErrNotObtainedError) Error() string
type NamespacedFeatureID ¶
func NewNamespacedFeatureID ¶
func NewNamespacedFeatureID(namespace string, id FeatureID) NamespacedFeatureID
type NamespacedGrantID ¶
func NewNamespacedGrantID ¶
func NewNamespacedGrantID(namespace string, id GrantID) NamespacedGrantID
type NamespacedLedgerID ¶
func NewNamespacedLedgerID ¶
func NewNamespacedLedgerID(namespace string, id LedgerID) NamespacedLedgerID
type Pagination ¶
type Reset ¶
type Reset struct {
Namespace string `json:"-"`
// ID is the readonly identifies of a reset.
ID *GrantID `json:"id,omitempty"`
// Subject The subject to grant the amount to.
LedgerID LedgerID `json:"ledgerID"`
// EffectiveAt The effective date, cannot be in the future.
EffectiveAt time.Time `json:"effectiveAt"`
}
Reset is used to reset the balance of a specific subject.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package credit_mock is a generated GoMock package.
|
Package credit_mock is a generated GoMock package. |