1
0
mirror of synced 2026-04-15 04:48:39 +08:00
Files
SnowFlake-IdGenerator/zzz-OtherLanguages/V/README.md
2021-04-12 20:25:56 +08:00

41 lines
803 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ❄ idgenerator-V
## 介绍
项目更多介绍参照https://github.com/yitter/idgenerator
## 运行环境
```sh
$ v --enable-globals run test.v
```
## 调用示例V
第1步**全局** 初始化(应用程序启动时执行一次):
```v ignore
// 定义全局变量
__global ( idgen gen.YitIdHelper ) //定义全局变量
// 使用默认参数配置
idgen = gen.YitIdHelper{
id_gen: gen.make_generator(&contract.IdGeneratorOptions{})
}
// 更改配置参数
idgen.set_id_generator(&contract.IdGeneratorOptions{
method: 1
base_time: 1582136402000
workerid_bitlength: 6
seq_bitlength: 10
})
//以上配置全局一次
```
第2步生成ID
```v ignore
// 初始化以后即可在任何需要生成ID的地方调用以下方法
newId := idgen.next_id()
```