Code Monkey home page Code Monkey logo

idgenerator-go's Introduction

❄ idgenerator-Go

介绍

项目更多介绍参照:https://github.com/yitter/idgenerator

引用全局库

go get -u -v github.com/yitter/[email protected]

调用示例(Go)

第1步,全局 初始化(应用程序启动时执行一次):

// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId:
var options = idgen.NewIdGeneratorOptions(1)
// options.WorkerIdBitLength = 10 // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。

// 保存参数(必须的操作,否则以上设置都不能生效):
idgen.SetIdGenerator(options)
// 以上初始化过程只需全局一次,且必须在第2步之前设置。

第2步,生成ID:

// 初始化以后,即可在任何需要生成ID的地方,调用以下方法:
var newId = idgen.NextId()

关于Go环境

1.SDK,go1.17

2.启用 Go-Modules

go env -w GO111MODULE=on

# Next *ONLY* for China-Users:
go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct

代码贡献者(按时间顺序)

guoyahao | amuluowin | houseme

idgenerator-go's People

Contributors

houseme avatar housemecn avatar varprob avatar yitter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

idgenerator-go's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.