idgen

package module
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package idgen provides the helpers functions.

Package idgen implements the functions, types, and interfaces for the module.

Index

Constants

This section is empty.

Variables

View Source
var StartNumber = int64(rand.Int32()) << 32

StartNumber is the start number of the randNumber.

Functions

func GenNumberID added in v0.2.15

func GenNumberID(name string) int64

func GenStringID added in v0.2.15

func GenStringID(name string) string

GenStringID The function "GenID" generates a new unique identifier and returns it as a string.

func RegisterNumberIdentifier added in v0.2.15

func RegisterNumberIdentifier(identifier NumberIdentifier)

func RegisterStringIdentifier added in v0.2.15

func RegisterStringIdentifier(identifier StringIdentifier)

RegisterStringIdentifier sets the defaultIdentifier randNumber.

func Size

func Size(name string) int

Size The function "Size" returns the size of the generated identifier

func Validate

func Validate[T ~string | ~int64](name string, id T) bool

Validate The function "Validate" checks whether the given identifier is valid or not.

Types

type NumberGenerator added in v0.2.15

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

func (*NumberGenerator) Name added in v0.2.15

func (obj *NumberGenerator) Name() string

Name returns the name of the object identifier.

func (*NumberGenerator) Number added in v0.2.15

func (obj *NumberGenerator) Number() int64

Number method generates an identifier.

func (*NumberGenerator) Size added in v0.2.15

func (obj *NumberGenerator) Size() int

Size method returns the size of the identifier.

func (*NumberGenerator) ValidateNumber added in v0.2.15

func (obj *NumberGenerator) ValidateNumber(id int64) bool

ValidateNumber method checks if the given identifier is valid.

type NumberIdentifier added in v0.2.15

type NumberIdentifier interface {
	Name() string
	Number() int64
	ValidateNumber(id int64) bool
	Size() int
}

NumberIdentifier is the interface of randNumber.

func GetNumberIdentifier added in v0.2.15

func GetNumberIdentifier(name string) NumberIdentifier

func NewNumber

func NewNumber(sta int64) NumberIdentifier

NewNumber method creates a new instance of the randNumber type.

type StringGenerator added in v0.2.15

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

func (*StringGenerator) Name added in v0.2.15

func (obj *StringGenerator) Name() string

Name returns the name of the object identifier.

func (*StringGenerator) Size added in v0.2.15

func (obj *StringGenerator) Size() int

Size method returns the size of the identifier.

func (*StringGenerator) String added in v0.2.15

func (obj *StringGenerator) String() string

String method generates an identifier.

func (*StringGenerator) ValidateString added in v0.2.15

func (obj *StringGenerator) ValidateString(id string) bool

ValidateString method checks if the given identifier is valid.

type StringIdentifier added in v0.2.15

type StringIdentifier interface {
	Name() string
	String() string
	ValidateString(id string) bool
	Size() int
}

StringIdentifier is the interface of randString.

func GetStringIdentifier added in v0.2.15

func GetStringIdentifier(name string) StringIdentifier

func NewString added in v0.2.15

func NewString() StringIdentifier

NewString method creates a new instance of the StringGenerator type.

Directories

Path Synopsis
Package snowflake provides a unique ID generation based on Twitter Snowflake algorithm.
Package snowflake provides a unique ID generation based on Twitter Snowflake algorithm.
Package ulid provides a ULID (Universally Unique Lexicographically Sortable Identifier) implementation.
Package ulid provides a ULID (Universally Unique Lexicographically Sortable Identifier) implementation.
Package uuid provides a UUID (Universally Unique Identifier) implementation.
Package uuid provides a UUID (Universally Unique Identifier) implementation.
Package xid provides a unique identifier generator based on xid.
Package xid provides a unique identifier generator based on xid.

Jump to

Keyboard shortcuts

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