auto commit
This commit is contained in:
@@ -8,21 +8,25 @@
|
|||||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.*" />
|
<PackageReference Include="Yitter.IdGenerator" Version="1.0.*" />
|
||||||
```
|
```
|
||||||
|
|
||||||
## 调用示例
|
## 调用示例(C#)
|
||||||
|
|
||||||
|
调用过程分为2步,第1步是全局初始化(应用程序启动时执行一次),第2步是生成ID,代码如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
// 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置)
|
// 第1步:创建 IdGeneratorOptions 对象,构造函数输入 WorkerId:
|
||||||
var options = new IdGeneratorOptions(){ WorkerId = 1};
|
var options = new IdGeneratorOptions(1);
|
||||||
|
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
|
||||||
|
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
|
||||||
|
// 保存参数(必须的操作,否则以上设置都不能生效):
|
||||||
YitIdHelper.SetIdGenerator(options);
|
YitIdHelper.SetIdGenerator(options);
|
||||||
|
// 以上初始化过程只需全局一次,且必须在第2步之前设置。
|
||||||
|
|
||||||
// 初始化以后,就可以在需要的地方调用方法生成ID。
|
// 第2步:初始化以后,即可在任何需要生成ID的地方,调用以下方法:
|
||||||
var newId = YitIdHelper.NextId();
|
var newId = YitIdHelper.NextId();
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,必须使用**单例**模式。
|
如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,必须使用**单例**模式。
|
||||||
|
|
||||||
## options 默认值及说明
|
|
||||||
|
|
||||||
参考源码:/Contract/IdGeneratorOptions.cs
|
|
||||||
|
|
||||||
## 事件说明
|
## 事件说明
|
||||||
|
|
||||||
|
|||||||
28
Go/README.md
28
Go/README.md
@@ -1,4 +1,4 @@
|
|||||||
# ❄️ idenerator-go
|
# ❄ idenerator-go
|
||||||
|
|
||||||
## 介绍
|
## 介绍
|
||||||
项目更多介绍参照:https://github.com/yitter/idgenerator
|
项目更多介绍参照:https://github.com/yitter/idgenerator
|
||||||
@@ -8,35 +8,33 @@
|
|||||||
1.SDK,go1.14
|
1.SDK,go1.14
|
||||||
|
|
||||||
2.启用 Go-Modules
|
2.启用 Go-Modules
|
||||||
|
|
||||||
```
|
```
|
||||||
go env -w GO111MODULE=on
|
go env -w GO111MODULE=on
|
||||||
|
|
||||||
# Next *ONLY* for China-Users:
|
# Next *ONLY* for China-Users:
|
||||||
go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
|
go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. 安装方式
|
3. 安装方式
|
||||||
|
|
||||||
```
|
```
|
||||||
go get -u -v github.com/yitter/idgenerator-go
|
go get -u -v github.com/yitter/idgenerator-go
|
||||||
```
|
```
|
||||||
|
|
||||||
## Go代码示例
|
## 调用示例(Go)
|
||||||
|
|
||||||
|
调用过程分为2步,第1步是全局初始化(应用程序启动时执行一次),第2步是生成ID,代码如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
// 第1步:创建 IdGeneratorOptions 对象,构造函数输入 WorkerId:
|
||||||
// 定义参数
|
var options = idgen.NewIdGeneratorOptions(1)
|
||||||
var options = idgen.NewIdGeneratorOptions(1) // 构造函数输入 WorkerId
|
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
|
||||||
// options.WorkerId = 1
|
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
|
||||||
// options.WorkerIdBitLength = 6
|
// 保存参数(必须的操作,否则以上设置都不能生效):
|
||||||
// options.SeqBitLength = 6
|
|
||||||
// ... 以上参数一般不需要设置,系统有默认值
|
|
||||||
idgen.SetIdGenerator(options)
|
idgen.SetIdGenerator(options)
|
||||||
|
// 以上初始化过程只需全局一次,且必须在第2步之前设置。
|
||||||
|
|
||||||
// 调用方法生成Id
|
// 第2步:初始化以后,即可在任何需要生成ID的地方,调用以下方法:
|
||||||
var id = idgen.NextId()
|
var newId = idgen.NextId()
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 代码贡献者(按时间顺序)
|
## 代码贡献者(按时间顺序)
|
||||||
|
|||||||
@@ -12,23 +12,23 @@ JDK 1.8+
|
|||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
## 调用示例
|
## 调用示例(Java)
|
||||||
|
|
||||||
|
调用过程分为2步,第1步是全局初始化(应用程序启动时执行一次),第2步是生成ID,代码如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
// 全局初始化设置WorkerId,默认最大2^16-1,可通过调整 WorkerIdBitLength 增加最大值
|
// 第1步:创建 IdGeneratorOptions 对象,构造函数输入 WorkerId:
|
||||||
IdGeneratorOptions options = new IdGeneratorOptions();
|
IdGeneratorOptions options = new IdGeneratorOptions(1);
|
||||||
options.WorkerId = 1;
|
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
|
||||||
|
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
|
||||||
|
// 保存参数(必须的操作,否则以上设置都不能生效):
|
||||||
YitIdHelper.setIdGenerator(options);
|
YitIdHelper.setIdGenerator(options);
|
||||||
// 以上初始化过程全局只需一次,且必须最先设置
|
// 以上初始化过程只需全局一次,且必须在第2步之前设置。
|
||||||
|
|
||||||
// 初始化以后,即可在需要生成ID的地方,调用以下方法。
|
// 第2步:初始化以后,即可在任何需要生成ID的地方,调用以下方法:
|
||||||
long newId = YitIdHelper.nextId();
|
long newId = YitIdHelper.nextId();
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,须使用**单例**模式。
|
如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,须使用**单例**模式。
|
||||||
|
|
||||||
|
|
||||||
## options 默认值及说明
|
|
||||||
|
|
||||||
参考源码:/contract/IdGeneratorOptions.java
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user