id

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 4 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyID

type AnyID = ID

AnyID is a type alias that accepts any valid prefix.

type CouponApplicationID

type CouponApplicationID = ID

CouponApplicationID identifies one coupon's application to one subscription.

type CouponID

type CouponID = ID

CouponID is a type-safe identifier for coupons (prefix: "cpn").

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 MustParse

func MustParse(s string) ID

MustParse is like Parse but panics on error. Use for hardcoded ID values.

func MustParseWithPrefix

func MustParseWithPrefix(s string, expected Prefix) ID

MustParseWithPrefix is like ParseWithPrefix but panics on error.

func New

func New(prefix Prefix) ID

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 NewCouponID

func NewCouponID() ID

NewCouponID generates a new unique coupon ID.

func NewEntitlementID

func NewEntitlementID() ID

NewEntitlementID generates a new unique entitlement ID.

func NewFeatureID

func NewFeatureID() ID

NewFeatureID generates a new unique feature ID.

func NewInvoiceID

func NewInvoiceID() ID

NewInvoiceID generates a new unique invoice ID.

func NewLineItemID

func NewLineItemID() ID

NewLineItemID generates a new unique line item ID.

func NewPaymentID

func NewPaymentID() ID

NewPaymentID generates a new unique payment ID.

func NewPlanID

func NewPlanID() ID

NewPlanID generates a new unique plan ID.

func NewPriceID

func NewPriceID() ID

NewPriceID generates a new unique price 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

func Parse(s string) (ID, error)

Parse parses a TypeID string (e.g., "plan_01h2xcejqtf2nbrexx3vqjhp41") into an ID. Returns an error if the string is not valid.

func ParseAny

func ParseAny(s string) (ID, error)

ParseAny parses a string into an ID without type checking the prefix.

func ParseCouponID

func ParseCouponID(s string) (ID, error)

ParseCouponID parses a string and validates the "cpn" prefix.

func ParseEntitlementID

func ParseEntitlementID(s string) (ID, error)

ParseEntitlementID parses a string and validates the "ent" prefix.

func ParseFeatureID

func ParseFeatureID(s string) (ID, error)

ParseFeatureID parses a string and validates the "feat" prefix.

func ParseInvoiceID

func ParseInvoiceID(s string) (ID, error)

ParseInvoiceID parses a string and validates the "inv" prefix.

func ParseLineItemID

func ParseLineItemID(s string) (ID, error)

ParseLineItemID parses a string and validates the "li" prefix.

func ParsePaymentID

func ParsePaymentID(s string) (ID, error)

ParsePaymentID parses a string and validates the "pay" prefix.

func ParsePlanID

func ParsePlanID(s string) (ID, error)

ParsePlanID parses a string and validates the "plan" prefix.

func ParsePriceID

func ParsePriceID(s string) (ID, error)

ParsePriceID parses a string and validates the "price" prefix.

func ParseSubscriptionID

func ParseSubscriptionID(s string) (ID, error)

ParseSubscriptionID parses a string and validates the "sub" prefix.

func ParseUsageEventID

func ParseUsageEventID(s string) (ID, error)

ParseUsageEventID parses a string and validates the "uevt" prefix.

func ParseWithPrefix

func ParseWithPrefix(s string, expected Prefix) (ID, error)

ParseWithPrefix parses a TypeID string and validates that its prefix matches the expected value.

func (ID) IsNil

func (i ID) IsNil() bool

IsNil reports whether this ID is the zero value.

func (ID) MarshalBSONValue

func (i ID) MarshalBSONValue() (bsonType byte, data []byte, err error)

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

func (i ID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (ID) Prefix

func (i ID) Prefix() Prefix

Prefix returns the prefix component of this ID.

func (*ID) Scan

func (i *ID) Scan(src any) error

Scan implements sql.Scanner for database retrieval.

func (ID) String

func (i ID) String() string

String returns the full TypeID string representation (prefix_suffix). Returns an empty string for the Nil ID.

func (*ID) UnmarshalBSONValue

func (i *ID) UnmarshalBSONValue(t byte, data []byte) error

UnmarshalBSONValue satisfies bson.ValueUnmarshaler (mongo-driver v2).

func (*ID) UnmarshalText

func (i *ID) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (ID) Value

func (i ID) Value() (driver.Value, error)

Value implements driver.Valuer for database storage. Returns nil for the Nil ID so that optional foreign key columns store NULL.

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 PlanID

type PlanID = ID

PlanID is a type-safe identifier for plans (prefix: "plan").

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 PriceID

type PriceID = ID

PriceID is a type-safe identifier for prices (prefix: "price").

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").

Jump to

Keyboard shortcuts

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