Documentation
¶
Overview ¶
Package ticketnumber provides ticket number generation implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AutoIncrement ¶
type AutoIncrement struct {
// contains filtered or unexported fields
}
func NewAutoIncrement ¶
func NewAutoIncrement(cfg Config) *AutoIncrement
func (*AutoIncrement) IsDateBased ¶
func (g *AutoIncrement) IsDateBased() bool
func (*AutoIncrement) Name ¶
func (g *AutoIncrement) Name() string
func (*AutoIncrement) Next ¶
func (g *AutoIncrement) Next(ctx context.Context, store CounterStore) (string, error)
type CounterStore ¶
type CounterStore interface {
// Add returns next counter given offset (>=1).
Add(ctx context.Context, dateScoped bool, offset int64) (int64, error)
}
CounterStore abstraction over ticket_number_counter algorithm.
type DBStore ¶
type DBStore struct {
// contains filtered or unexported fields
}
We maintain exactly one row per counter_uid and atomically increment using dialect specific UPSERT:
Postgres: INSERT ... ON CONFLICT(counter_uid) DO UPDATE SET counter = ticket_number_counter.counter + EXCLUDED.counter RETURNING counter MySQL: INSERT ... ON DUPLICATE KEY UPDATE counter = LAST_INSERT_ID(counter + VALUES(counter)); SELECT LAST_INSERT_ID()
dateScoped controls daily UID suffix (YYYYMMDD) for date-based generators.
type Date ¶
type Date struct {
// contains filtered or unexported fields
}
func (*Date) IsDateBased ¶
type DateChecksum ¶
type DateChecksum struct {
// contains filtered or unexported fields
}
DateChecksum: yyyymmdd + SystemID + zero-padded counter (min 5) + single check digit. Check digit: sum over digits with multipliers 1,2,1,2... ; sum each product directly; checksum = 10 - (sum % 10); if result == 10 => 1.
func NewDateChecksum ¶
func NewDateChecksum(cfg Config, clk Clock) *DateChecksum
func (*DateChecksum) IsDateBased ¶
func (g *DateChecksum) IsDateBased() bool
func (*DateChecksum) Name ¶
func (g *DateChecksum) Name() string
func (*DateChecksum) Next ¶
func (g *DateChecksum) Next(ctx context.Context, store CounterStore) (string, error)
type Generator ¶
type Generator interface {
Name() string
Next(ctx context.Context, store CounterStore) (string, error)
IsDateBased() bool
}
Generator defines contract for ticket number generators.
type Random ¶
type Random struct {
// contains filtered or unexported fields
}
Random generator: SystemID + 8 random digits (collision resolved by retry via store if needed).
func (*Random) IsDateBased ¶
type SetupResult ¶
func SetupFromConfig ¶
func SetupFromConfig(configDir string) SetupResult
SetupFromConfig resolves SystemID and Ticket::NumberGenerator from config and returns a generator (no DB store binding yet).