util

package
v0.0.0-...-29e355a Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateMachineIDByMac

func GenerateMachineIDByMac(machineBitLen int64) int64

Types

type IDGenerator

type IDGenerator interface {
	GenerateID() int64
}

type SnowFlakeOption

type SnowFlakeOption struct {
	StartTime    time.Time
	TimestampBit int64
	MachineBit   int64
	SequenceBit  int64
	MachineID    int64
	TimeUnit     time.Duration
}

type Snowflake

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

func NewSmallSnowflake

func NewSmallSnowflake(machineID int64) (*Snowflake, error)

NewSmallSnowflake

Snowflake Structure: -------------------- | Timestamp | Machine ID | Sequence | --------------------------------------- | 32 bits | 5 bits | 15 bits | ---------------------------------------

Some environments cannot use bd NTID, and a front-end friendly id is required.

func NewSnowflake

func NewSnowflake(ctx context.Context, option *SnowFlakeOption) (*Snowflake, error)

func NewStandardSnowflake

func NewStandardSnowflake(machineID int64) (*Snowflake, error)

func (*Snowflake) GenerateID

func (s *Snowflake) GenerateID() int64

Jump to

Keyboard shortcuts

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