hash

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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

View Source
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

View Source
var SpaceReplacementTests = []struct {
	input    string
	expected string
}{
	{"US R", "USXR"},
	{"U R ", "UXRX"},
	{" US ", "XUSX"},
	{"   U", "XXXU"},
}

Test data for TestSpaceReplacementInTableIdentifier

View Source
var TableSizeFormatTests = []struct {
	size           TableSize
	expectedLength int
}{
	{Tiny, 8},
	{Small, 10},
	{Medium, 12},
	{Large, 14},
	{XLarge, 16},
}

Test data for TestTableSizeFormats

Functions

func GenerateRandomID

func GenerateRandomID(tableIdentifier string, size TableSize) (string, error)

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

func GetModelTypeFromHash(hashID string) string

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 NewIDGenerator

func NewIDGenerator() *IDGenerator

NewIDGenerator creates a new ID generator

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

type TableSize

type TableSize string

TableSize represents the size category of a table

const (
	Tiny   TableSize = "tiny"   // 4 digits
	Small  TableSize = "small"  // 6 digits
	Medium TableSize = "medium" // 8 digits
	Large  TableSize = "large"  // 10 digits
	XLarge TableSize = "xlarge" // 12 digits
)

Jump to

Keyboard shortcuts

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