ticketnumber

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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 Clock

type Clock interface{ Now() TimeParts }

Clock allows deterministic testing.

type Config

type Config struct {
	SystemID                string
	MinCounterSize          int
	DateUseFormattedCounter bool
}

Config needed by generators.

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.

func NewDBStore

func NewDBStore(db *sql.DB, systemID string) *DBStore

func (*DBStore) Add

func (s *DBStore) Add(ctx context.Context, dateScoped bool, offset int64) (int64, error)

Add implements CounterStore. offset currently only supports 1. Larger offsets map to repeated increments.

type Date

type Date struct {
	// contains filtered or unexported fields
}

func NewDate

func NewDate(cfg Config, clk Clock) *Date

func (*Date) IsDateBased

func (g *Date) IsDateBased() bool

func (*Date) Name

func (g *Date) Name() string

func (*Date) Next

func (g *Date) Next(ctx context.Context, store CounterStore) (string, error)

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.

func Resolve

func Resolve(name string, systemID string, clk Clock) (Generator, error)

Resolve maps a configured generator name and systemID to a concrete Generator. Names must match schema options exactly (case-insensitive match for leniency). Valid: Increment, Date, DateChecksum, Random.

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 NewRandom

func NewRandom(cfg Config, seed int64) *Random

func (*Random) IsDateBased

func (g *Random) IsDateBased() bool

func (*Random) Name

func (g *Random) Name() string

func (*Random) Next

func (g *Random) Next(ctx context.Context, store CounterStore) (string, error)

type SetupResult

type SetupResult struct {
	Generator Generator
	SystemID  string
	Name      string
}

func SetupFromConfig

func SetupFromConfig(configDir string) SetupResult

SetupFromConfig resolves SystemID and Ticket::NumberGenerator from config and returns a generator (no DB store binding yet).

type TimeParts

type TimeParts struct {
	Year  int
	Month int
	Day   int
}

TimeParts minimal date parts.

Jump to

Keyboard shortcuts

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