Skip to content
/ leaf Public
forked from xingliuhua/leaf

generate a unique id(Contains numbers and letters),You can specify the length.(go 唯一订单ID生成器,字母+数字组合)

Notifications You must be signed in to change notification settings

a7600999/leaf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

中文版

leaf

This is a variant of Twitter snowflake. Generates a unique string of 10 length,contains letters and numbers,it can be used for 89 year. generates a unique string(Contains numbers and letters) of 10 length,Each node can generate 36 ids per millisecond.

Background

We often need a unique ID of ten lengths,Twitter snowflake is too long.

Feature

00000000-0-0...

It was divided into three groups:

  1. timeStamp 36^8 = 2.821109907456e+12 millisecond > 89 * 365 * 24 *3600 * 1000 it can use 89 years.leaf

  2. nodeId 0<= nodeId <=35

  3. rate default 36 ids per millisecond. you can customize it.

Install

go get github.com/xingliuhua/leaf

Usage

import "github.com/xingliuhua/leaf"
    err, node := leaf.NewNode(0)
   	if err != nil {
   		return
   	}
   	err = node.SetGenerateIDRate(200)
   	if err != nil {
   		return
   	}
   	startTime := time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).UnixNano() / 1000000
   	err = node.SetSince(startTime)
   	if err != nil {
   		return
   	}
   	for i := 0; i < 40; i++ {
   		err, id := node.NextId()
   		if err != nil {
   			return
   		}
   		fmt.Println(id)
   	}

Maintainers

@xingliuhua.

Contributing

Feel free to dive in! [Open an issue] or submit PRs.

About

generate a unique id(Contains numbers and letters),You can specify the length.(go 唯一订单ID生成器,字母+数字组合)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%