idGen

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDataCenterIDMax

func GetDataCenterIDMax() int64

func GetDeviceID

func GetDeviceID(sid int64) (datacenterid, workerid int64)

GetDeviceID 获取数据中心ID和机器ID.

func GetGenTime

func GetGenTime(sid int64, layout string) (t string)

GetGenTime 获取创建ID时的时间字符串(精度:秒)

func GetGenTimestamp

func GetGenTimestamp(sid int64) (timestamp int64)

GetGenTimestamp 获取创建ID时的时间戳

func GetTimestamp

func GetTimestamp(sid int64) (timestamp int64)

GetTimestamp 获取时间戳

func GetTimestampStatus

func GetTimestampStatus() (state float64)

GetTimestampStatus 获取时间戳已使用的占比:范围(0.0 - 1.0)

func GetWorkerIDMax

func GetWorkerIDMax() int64

func NewUUID4

func NewUUID4() (uuid4 string)

Types

type IDGenerator

type IDGenerator interface {
	NextID() (int64, error)
	GetDeviceID(sid int64) (datacenterid, workerid int64)
	GetTimestamp(sid int64) (timestamp int64)
	GetGenTimestamp(sid int64) (timestamp int64)
	GetGenTime(sid int64, layout string) (t string)
	GetTimestampStatus() (state float64)
}

func Default

func Default() IDGenerator

func NewSnowflake

func NewSnowflake(datacenterid, workerid int64) (IDGenerator, error)

type Snowflake

type Snowflake struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Snowflake) GetDeviceID

func (s *Snowflake) GetDeviceID(sid int64) (datacenterid, workerid int64)

GetDeviceID 获取数据中心ID和机器ID.

func (*Snowflake) GetGenTime

func (s *Snowflake) GetGenTime(sid int64, layout string) (t string)

GetGenTime 获取创建ID时的时间字符串(精度:秒).

func (*Snowflake) GetGenTimestamp

func (s *Snowflake) GetGenTimestamp(sid int64) (timestamp int64)

GetGenTimestamp 获取创建ID时的时间戳.

func (*Snowflake) GetTimestamp

func (s *Snowflake) GetTimestamp(sid int64) (timestamp int64)

GetTimestamp 获取时间戳.

func (*Snowflake) GetTimestampStatus

func (s *Snowflake) GetTimestampStatus() (state float64)

GetTimestampStatus 获取时间戳已使用的占比:范围(0.0 - 1.0.

func (*Snowflake) NextID

func (s *Snowflake) NextID() (int64, error)

Jump to

Keyboard shortcuts

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