#### 项目github
> https://github.com/HaroldHoo/id_generator
#### 相关文章
> https://www.yaolong.me/2017/10/id-generator/
# id_generator
## Layout
```
|<----timestamp---->|<-----ExtraID----->|
layout: [-------------------|----|------|-------]
64 32 0
|<InstID>|<-DataID->|<---NextID--->|
ExtraID: [--------|----------|--------------]
32 24 14 0
InstID: Machine Instance ID, like IP, 8bit.
(可配置的,机器或实例ID,比如IP末位等)
DataID: Data ID, like Mysql table ID Or UserID, 10bit.
(可配置的,数据ID,比如分表的ID、用户ID等)
NextId: A Increment Number in the same second, 14bit.
(自生成的,每秒内增序数,以保证唯一)
```
## Example
```
import "github.com/HaroldHoo/id_generator"
```
```
// Machine Instance ID, like IP, 8bit (全局设置8bit的机器ID)
id_generator.DefaultInstanceId = 154
// Data ID, like Mysql table ID, 10bit (设置10bit的数据ID)
var dataID = uint64(256)
// generate (生成ID)
id,_ := id_generator.NextId(dataID)
```