Documentation
¶
Index ¶
- func Query(db *datastore.Datastore) datastore.Query
- type CreditGrant
- func (g *CreditGrant) Defaults()
- func (g *CreditGrant) IsActive() bool
- func (g *CreditGrant) IsEligibleForMeter(meterId string) bool
- func (g *CreditGrant) Load(ps []datastore.Property) (err error)
- func (g *CreditGrant) Save() (ps []datastore.Property, err error)
- func (g *CreditGrant) Validator() *val.Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 New(db *datastore.Datastore) *CreditGrant
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) Validator ¶
func (g *CreditGrant) Validator() *val.Validator
Click to show internal directories.
Click to hide internal directories.