snowflake_id

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandU32N

func RandU32N(n uint32) uint32

func WorkerIDFromIP

func WorkerIDFromIP(ipv4 net.IP) uint32

func WorkerIDFromLocalIP

func WorkerIDFromLocalIP() (uint32, error)

Types

type Snowflake

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

func NewSnowflake

func NewSnowflake(worker uint32) (*Snowflake, error)

func (*Snowflake) ID

func (s *Snowflake) ID() (uint64, error)

func (*Snowflake) WorkerID

func (s *Snowflake) WorkerID() uint32

type SnowflakeFactory

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

SnowflakeFactory to build snowflake id |---worker id---|---sequence---|---timestamp---|

func NewSnowflakeFactory

func NewSnowflakeFactory(bitsWorkerID, bitsSequence uint32, gap uint32, base time.Time) *SnowflakeFactory

func (*SnowflakeFactory) Build

func (f *SnowflakeFactory) Build(workerID, seq uint32, elapsed uint64) (uint64, error)

func (*SnowflakeFactory) Duration

func (f *SnowflakeFactory) Duration(ts time.Time, d time.Duration) time.Duration

func (*SnowflakeFactory) Elapsed

func (f *SnowflakeFactory) Elapsed(ts time.Time) uint64

Elapsed units from now to base

func (*SnowflakeFactory) MaskSequence

func (f *SnowflakeFactory) MaskSequence(seq uint32) uint32

func (*SnowflakeFactory) New

func (f *SnowflakeFactory) New(workerID uint32) (*Snowflake, error)

func (*SnowflakeFactory) String

func (f *SnowflakeFactory) String() string

func (*SnowflakeFactory) Units

func (f *SnowflakeFactory) Units(t time.Time) uint64

Units returns snowflake units since `t`

Jump to

Keyboard shortcuts

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