Documentation
¶
Index ¶
- Constants
- func ExtractComponents(ticketID string) map[string]string
- func Format(ticketID string) string
- func Generate(eventID string, eventDate time.Time, categoryID string, seatID string, ...) (string, error)
- func GenerateSequence() int
- func IsValidTicketIDFormat(ticketID string) bool
- func RemoveDashes(ticketID string) string
- func WrapError(code, message string, err error) error
- type Error
- type TicketID
Constants ¶
const ( ErrInvalidEventID = "INVALID_EVENT_ID" ErrInvalidDate = "INVALID_DATE" ErrInvalidCategory = "INVALID_CATEGORY" ErrInvalidSeat = "INVALID_SEAT" ErrInvalidSequence = "INVALID_SEQUENCE" ErrInvalidTicketID = "INVALID_TICKET_ID" ErrDecodeFailed = "DECODE_FAILED" ErrInvalidChecksum = "INVALID_CHECKSUM" ErrInvalidLength = "INVALID_LENGTH" ErrValueOutOfRange = "VALUE_OUT_OF_RANGE" )
Error codes
const ( EventIDLength = 5 // 33.5M unique events EventDateLength = 5 // YYYYMMDD encoded CategoryLength = 3 // 32,768 categories SeatIDLength = 5 // 33.5M seats SequenceLength = 4 // 1M sequences ChecksumLength = 2 // 2-char CRC-10 // TotalLength: 5+5+3+5+4+2 = 24 characters TotalLength = EventIDLength + EventDateLength + CategoryLength + SeatIDLength + SequenceLength + ChecksumLength )
Ticket ID component lengths (in Base32 characters)
Variables ¶
This section is empty.
Functions ¶
func ExtractComponents ¶
ExtractComponents extracts raw component strings without decoding
func Format ¶
Format formats a ticket ID with dashes for readability Example: 01B2M4K6G8N3V9F2HA7XJ5QR → 01B2M-4K6G8-N3V-9F2HA-7XJ5-QR
func Generate ¶
func Generate( eventID string, eventDate time.Time, categoryID string, seatID string, sequence int, ) (string, error)
Generate creates a unique ticket ID from the given components Format: [EEEEE][DDDDD][CCC][SSSSS][RRRR][XX] Example: 01B2M4K6G8N3V9F2HA7XJ5QR
func GenerateSequence ¶
func GenerateSequence() int
GenerateSequence generates a unique sequence number based on timestamp and randomness This provides collision resistance while being reproducible if needed
func IsValidTicketIDFormat ¶
IsValidTicketIDFormat validates ticket ID format without decoding
func RemoveDashes ¶
RemoveDashes removes all dashes from a ticket ID
Types ¶
type Error ¶
Error represents a ticket ID operation error
func NewErrorWithDetails ¶
NewErrorWithDetails creates a new Error with details
type TicketID ¶
type TicketID struct {
EventID string `json:"eventId" msgpack:"e"`
EventDate time.Time `json:"eventDate" msgpack:"d"`
CategoryID string `json:"categoryId" msgpack:"c"`
SeatID string `json:"seatId" msgpack:"s"`
Sequence int `json:"sequence" msgpack:"q"`
EncodedID string `json:"encodedId" msgpack:"i"`
Checksum string `json:"checksum" msgpack:"k"`
}
TicketID represents the decoded components of a ticket ID
func DecodeTicketID ¶
DecodeTicketID decodes a ticket ID string into its components Validates checksum and extracts all encoded data
func ParseTicketID ¶
ParseTicketID is an alias for DecodeTicketID