Coder Social home page Coder Social logo

idgen's Introduction

id generator

Build Status license

介绍

  • 基于snowflake算法实现的id生成器
  • 这是go版本,java版本可查看IdWorker.java

使用

go get github.com/sumory/idgen

使用前请先了解snowflake算法,并知晓其注意事项.

基本使用

每个由idgen生成的id都是int64的正整数,且每个id都可以解析得到它的生成者的标识workerId.

workerId := 1
err, idWorker := idgen.NewIdWorker(workerId)
err, nextId := idWorker.NextId()
获取short Id

idgen使用baseN4go缩短id,具体参见baseN4go使用方法.

workerId := 1
err, idWorker := idgen.NewIdWorker(workerId)
err, nextId := idWorker.ShortId()
获取生成器标识workerId
workerId := 1
err, idWorker := idgen.NewIdWorker(workerId)
err, nextId := idWorker.NextId()
wId := idWorker.WorkerId(newId)//wId == workerId
其它

参见测试文件idgen_test.go和源文件

测试

需要goconvey支持

go get github.com/smartystreets/goconvey
go test -v -cover // or $GOPATH/bin/goconvey

idgen's People

Contributors

sumory avatar

Watchers

 avatar

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.