snowflake

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 4 Imported by: 0

README

snowflake

goSnowFlake基础上封装库。


安装

go get -u gitee.com/yzsunjianguo/sponge/pkg/snowflake


使用示例

    // 初始化
    snowflake.Init(1)

    // 生成id
    id := snowflake.NewID()

生产id性能测试

os: windows
goarch: amd64
cpu: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
BenchmarkNewID-12       47746561                24.72 ns/op            0 B/op          0 allocs/op
PASS
ok      command-line-arguments  1.261s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(workID int64) error

Init 初始化SnowFlake

func NewID

func NewID() int64

NewID create new id

Types

type IDWorker

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

IDWorker Struct

func NewIDWorker

func NewIDWorker(workerID int64) (iw *IDWorker, err error)

NewIDWorker Func: Generate NewIdWorker with Given workerId

func (*IDWorker) NextID

func (iw *IDWorker) NextID() (ts int64, err error)

NextID return the id

Jump to

Keyboard shortcuts

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