creditgrant

package
v1.46.21 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

Types

type CreditGrant

type CreditGrant struct {
	mixin.Model[CreditGrant]

	UserId         string        `json:"userId"`
	Name           string        `json:"name"`
	AmountCents    int64         `json:"amountCents"`
	RemainingCents int64         `json:"remainingCents"`
	Currency       currency.Type `json:"currency" orm:"default:usd"`

	EffectiveAt time.Time `json:"effectiveAt"`
	ExpiresAt   time.Time `json:"expiresAt,omitempty"`

	// Lower priority = burn first
	Priority int `json:"priority"`

	// JSON: list of meter IDs this grant applies to (empty = all meters)
	Eligibility  []string `json:"eligibility,omitempty" datastore:"-"`
	Eligibility_ string   `json:"-" datastore:",noindex"`

	// Searchable tags: "promo", "purchased", "earned"
	Tags string `json:"tags,omitempty"`

	Voided bool `json:"voided"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

CreditGrant represents a discrete credit allocation for a user. Grants can have expiry dates, priority ordering, and meter eligibility restrictions. The burn-down algorithm consumes grants in priority order (lower priority number = consumed first), then by earliest expiry.

func New

func (*CreditGrant) Defaults

func (g *CreditGrant) Defaults()

Defaults sets runtime-computed defaults that cannot be expressed as struct tags.

func (*CreditGrant) IsActive

func (g *CreditGrant) IsActive() bool

IsActive returns true if the grant is usable right now.

func (*CreditGrant) IsEligibleForMeter

func (g *CreditGrant) IsEligibleForMeter(meterId string) bool

IsEligibleForMeter checks if this grant can be applied to a given meter. Empty eligibility means eligible for all meters.

func (*CreditGrant) Load

func (g *CreditGrant) Load(ps []datastore.Property) (err error)

func (*CreditGrant) Save

func (g *CreditGrant) Save() (ps []datastore.Property, err error)

func (*CreditGrant) Validator

func (g *CreditGrant) Validator() *val.Validator

Jump to

Keyboard shortcuts

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