Documentation ¶
Index ¶
- func RandU32N(n uint32) uint32
- func WorkerIDFromIP(ipv4 net.IP) uint32
- func WorkerIDFromLocalIP() (uint32, error)
- type Snowflake
- type SnowflakeFactory
- func (f *SnowflakeFactory) Build(workerID, seq uint32, elapsed uint64) (uint64, error)
- func (f *SnowflakeFactory) Duration(ts time.Time, d time.Duration) time.Duration
- func (f *SnowflakeFactory) Elapsed(ts time.Time) uint64
- func (f *SnowflakeFactory) MaskSequence(seq uint32) uint32
- func (f *SnowflakeFactory) New(workerID uint32) (*Snowflake, error)
- func (f *SnowflakeFactory) String() string
- func (f *SnowflakeFactory) Units(t time.Time) uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WorkerIDFromIP ¶
func WorkerIDFromLocalIP ¶
Types ¶
type Snowflake ¶
type Snowflake struct {
// contains filtered or unexported fields
}
func NewSnowflake ¶
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) 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) String ¶
func (f *SnowflakeFactory) String() string
Click to show internal directories.
Click to hide internal directories.