Documentation
¶
Overview ¶
Package id defines TypeID-based identity types for all Ledger entities.
Every entity in Ledger uses a single ID struct with a prefix that identifies the entity type. IDs are K-sortable (UUIDv7-based), globally unique, and URL-safe in the format "prefix_suffix".
Index ¶
- type AnyID
- type CouponApplicationID
- type CouponID
- type EntitlementID
- type FeatureID
- type ID
- func MustParse(s string) ID
- func MustParseWithPrefix(s string, expected Prefix) ID
- func New(prefix Prefix) ID
- func NewCouponApplicationID() ID
- func NewCouponID() ID
- func NewEntitlementID() ID
- func NewFeatureID() ID
- func NewInvoiceID() ID
- func NewLineItemID() ID
- func NewPaymentID() ID
- func NewPlanID() ID
- func NewPriceID() ID
- func NewSubscriptionID() ID
- func NewUsageEventID() ID
- func Parse(s string) (ID, error)
- func ParseAny(s string) (ID, error)
- func ParseCouponID(s string) (ID, error)
- func ParseEntitlementID(s string) (ID, error)
- func ParseFeatureID(s string) (ID, error)
- func ParseInvoiceID(s string) (ID, error)
- func ParseLineItemID(s string) (ID, error)
- func ParsePaymentID(s string) (ID, error)
- func ParsePlanID(s string) (ID, error)
- func ParsePriceID(s string) (ID, error)
- func ParseSubscriptionID(s string) (ID, error)
- func ParseUsageEventID(s string) (ID, error)
- func ParseWithPrefix(s string, expected Prefix) (ID, error)
- func (i ID) IsNil() bool
- func (i ID) MarshalBSONValue() (bsonType byte, data []byte, err error)
- func (i ID) MarshalText() ([]byte, error)
- func (i ID) Prefix() Prefix
- func (i *ID) Scan(src any) error
- func (i ID) String() string
- func (i *ID) UnmarshalBSONValue(t byte, data []byte) error
- func (i *ID) UnmarshalText(data []byte) error
- func (i ID) Value() (driver.Value, error)
- type InvoiceID
- type LineItemID
- type PaymentID
- type PlanID
- type Prefix
- type PriceID
- type SubscriptionID
- type UsageEventID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CouponApplicationID ¶
type CouponApplicationID = ID
CouponApplicationID identifies one coupon's application to one subscription.
type EntitlementID ¶
type EntitlementID = ID
EntitlementID is a type-safe identifier for entitlements (prefix: "ent").
type FeatureID ¶
type FeatureID = ID
FeatureID is a type-safe identifier for features (prefix: "feat").
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID is the primary identifier type for all Ledger entities. It wraps a TypeID providing a prefix-qualified, globally unique, sortable, URL-safe identifier in the format "prefix_suffix".
var Nil ID
Nil is the zero-value ID.
func MustParseWithPrefix ¶
MustParseWithPrefix is like ParseWithPrefix but panics on error.
func New ¶
New generates a new globally unique ID with the given prefix. It panics if prefix is not a valid TypeID prefix (programming error).
func NewCouponApplicationID ¶
func NewCouponApplicationID() ID
NewCouponApplicationID returns a new random CouponApplicationID.
func NewEntitlementID ¶
func NewEntitlementID() ID
NewEntitlementID generates a new unique entitlement ID.
func NewSubscriptionID ¶
func NewSubscriptionID() ID
NewSubscriptionID generates a new unique subscription ID.
func NewUsageEventID ¶
func NewUsageEventID() ID
NewUsageEventID generates a new unique usage event ID.
func Parse ¶
Parse parses a TypeID string (e.g., "plan_01h2xcejqtf2nbrexx3vqjhp41") into an ID. Returns an error if the string is not valid.
func ParseCouponID ¶
ParseCouponID parses a string and validates the "cpn" prefix.
func ParseEntitlementID ¶
ParseEntitlementID parses a string and validates the "ent" prefix.
func ParseFeatureID ¶
ParseFeatureID parses a string and validates the "feat" prefix.
func ParseInvoiceID ¶
ParseInvoiceID parses a string and validates the "inv" prefix.
func ParseLineItemID ¶
ParseLineItemID parses a string and validates the "li" prefix.
func ParsePaymentID ¶
ParsePaymentID parses a string and validates the "pay" prefix.
func ParsePlanID ¶
ParsePlanID parses a string and validates the "plan" prefix.
func ParsePriceID ¶
ParsePriceID parses a string and validates the "price" prefix.
func ParseSubscriptionID ¶
ParseSubscriptionID parses a string and validates the "sub" prefix.
func ParseUsageEventID ¶
ParseUsageEventID parses a string and validates the "uevt" prefix.
func ParseWithPrefix ¶
ParseWithPrefix parses a TypeID string and validates that its prefix matches the expected value.
func (ID) MarshalBSONValue ¶
MarshalBSONValue satisfies bson.ValueMarshaler (mongo-driver v2) so the ID is stored as a BSON string instead of an opaque struct. No bson import needed because Go uses structural typing for interface satisfaction.
func (ID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (ID) String ¶
String returns the full TypeID string representation (prefix_suffix). Returns an empty string for the Nil ID.
func (*ID) UnmarshalBSONValue ¶
UnmarshalBSONValue satisfies bson.ValueUnmarshaler (mongo-driver v2).
func (*ID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type InvoiceID ¶
type InvoiceID = ID
InvoiceID is a type-safe identifier for invoices (prefix: "inv").
type LineItemID ¶
type LineItemID = ID
LineItemID is a type-safe identifier for line items (prefix: "li").
type PaymentID ¶
type PaymentID = ID
PaymentID is a type-safe identifier for payments (prefix: "pay").
type Prefix ¶
type Prefix string
Prefix identifies the entity type encoded in a TypeID.
const ( PrefixPlan Prefix = "plan" // Billing plan PrefixFeature Prefix = "feat" // Plan feature PrefixPrice Prefix = "price" // Pricing configuration PrefixSubscription Prefix = "sub" // Customer subscription PrefixUsageEvent Prefix = "uevt" // Usage event PrefixEntitlement Prefix = "ent" // Entitlement check result PrefixInvoice Prefix = "inv" // Invoice PrefixLineItem Prefix = "li" // Invoice line item PrefixCoupon Prefix = "cpn" // Discount coupon PrefixPayment Prefix = "pay" // Payment record PrefixCouponApplication Prefix = "cpna" // Coupon applied to a subscription )
Prefix constants for all Ledger entity types.
type SubscriptionID ¶
type SubscriptionID = ID
SubscriptionID is a type-safe identifier for subscriptions (prefix: "sub").
type UsageEventID ¶
type UsageEventID = ID
UsageEventID is a type-safe identifier for usage events (prefix: "uevt").