Documentation
¶
Index ¶
- Variables
- func GenerateRandomID(tableIdentifier string, size TableSize) (string, error)
- func GenerateRandomIDWithPattern(tableIdentifier string, size TableSize, pattern string) (string, error)
- func GetModelTypeFromHash(hashID string) string
- func InitializeGlobalCountersFromDatabase(tableIdentifier string, existingIDs []string, size TableSize)
- type IDGenerator
- func (g *IDGenerator) GenerateID(tableIdentifier string, size TableSize, pattern string) (string, error)
- func (g *IDGenerator) InitializeCountersFromDatabase(tableIdentifier string, existingIDs []string)
- func (g *IDGenerator) InitializeCountersFromDatabaseWithSize(tableIdentifier string, existingIDs []string, size TableSize)
- type TableSize
Constants ¶
This section is empty.
Variables ¶
var GenerateRandomIDTests = []struct { name string tableIdentifier string size TableSize expectedPrefix string expectedLength int shouldError bool }{ { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, }
Test data for TestGenerateRandomID
var GenerateRandomIDWithPatternTests = []struct { name string tableIdentifier string size TableSize pattern string expectedPrefix string expectedLength int shouldError bool }{ { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, }
Test data for TestGenerateRandomIDWithPattern
var GetModelTypeFromHashTests = []struct { name string hashID string expected string }{ { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, { // contains filtered or unexported fields }, }
Test data for TestGetModelTypeFromHash
var SpaceReplacementTests = []struct { input string expected string }{ {"US R", "USXR"}, {"U R ", "UXRX"}, {" US ", "XUSX"}, {" U", "XXXU"}, }
Test data for TestSpaceReplacementInTableIdentifier
var TableSizeFormatTests = []struct { size TableSize expectedLength int }{ {Tiny, 8}, {Small, 10}, {Medium, 12}, {Large, 14}, {XLarge, 16}, }
Test data for TestTableSizeFormats
Functions ¶
func GenerateRandomID ¶
GenerateRandomID generates a unique ID for a model based on table identifier and size
func GenerateRandomIDWithPattern ¶
func GenerateRandomIDWithPattern(tableIdentifier string, size TableSize, pattern string) (string, error)
GenerateRandomIDWithPattern generates a unique ID with a specific pattern
func GetModelTypeFromHash ¶
GetModelTypeFromHash extracts the model type from a hash ID. The model type is represented by the first 4 characters of the hash ID, which corresponds to the table identifier used during ID generation. If the hash ID is shorter than 4 characters, returns the entire hash ID.
func InitializeGlobalCountersFromDatabase ¶ added in v0.1.3
func InitializeGlobalCountersFromDatabase(tableIdentifier string, existingIDs []string, size TableSize)
InitializeGlobalCountersFromDatabase initializes the global generator's counters from database
Types ¶
type IDGenerator ¶
type IDGenerator struct {
// contains filtered or unexported fields
}
IDGenerator manages ID generation for different tables. It maintains a thread-safe map of counters for each table to generate unique incremental IDs. The counters map stores the last used ID value for each table identifier. The mutex (mu) ensures thread-safe access to the counters when multiple goroutines generate IDs concurrently.
func (*IDGenerator) GenerateID ¶
func (g *IDGenerator) GenerateID(tableIdentifier string, size TableSize, pattern string) (string, error)
GenerateID generates a unique ID based on table identifier, size, and pattern
func (*IDGenerator) InitializeCountersFromDatabase ¶ added in v0.1.3
func (g *IDGenerator) InitializeCountersFromDatabase(tableIdentifier string, existingIDs []string)
InitializeCountersFromDatabase initializes the counters from existing database records This prevents duplicate key violations when the service restarts
func (*IDGenerator) InitializeCountersFromDatabaseWithSize ¶ added in v0.1.3
func (g *IDGenerator) InitializeCountersFromDatabaseWithSize(tableIdentifier string, existingIDs []string, size TableSize)
InitializeCountersFromDatabaseWithSize initializes counters considering the table size