JS>> rid>> 返回
项目作者: itrabbit

项目描述 :
Unique ID Generator
高级语言: Go
项目地址: git://github.com/itrabbit/rid.git
创建时间: 2018-02-14T13:58:48Z
项目社区:https://github.com/itrabbit/rid

开源协议:MIT License

下载


Unique ID Generator

Use 6 byte for submission time (UTC). You can use for SQL.

! Limit values to 2310 year.

Identifier structure:

  • 1-byte hardware address CRC4 ID

  • 2-byte process id

  • 4-byte value representing the seconds since the 2018-01-01 epoch

  • 3-byte counter (random, or manual)

  • 2-byte nanoseconds (the first 2 bytes of the four byte value)

Install

  1. go get github.com/itrabbit/rid

Usage

  1. fmt.Println(rid.New())
  2. // -> t9eti00dzt0e0hkibo9g
  3. fmt.Println(rid.New().String())
  4. // -> t9ew400dzt1db4okkw80
  5. fmt.Println(rid.New().NumeralString())
  6. // -> 218093205000013254195242051055202176

Custom source:

  1. src := rid.NewSource()
  2. // src.Seed(0) <- Set start counter by custom value
  3. id := src.NewID()

Get embedded info:

  1. id := rid.New()
  2. id.Mid() // Hardware Address CRC ID
  3. id.Pid() // Process Pid
  4. id.Time() // With an accuracy of up to 6 bytes (from 8)
  5. id.Counter()

Copyright (c) 2018 IT Rabbit.

Original encode/decode algorithm: Copyright (c) 2015 Olivier Poitrey rs@dailymotion.com. The same MIT license applies.