git.zd.zone/hrpc/hrpc@v0.0.12/utils/uniqueid/README.md (about) 1 # 生成全局唯一ID 2 3 示例: 4 5 ```go 6 func TestGetUniqueID(t *testing.T) { 7 err := Register() 8 if err != nil { 9 t.Error(err) 10 } 11 12 nodeMap := make(map[int64]int) 13 for i := 1; i < 10000; i++ { 14 uniqueID := New().Number() 15 if id, ok := nodeMap[uniqueID]; ok { 16 t.Error(id) 17 } else { 18 nodeMap[uniqueID] = i 19 } 20 } 21 t.Log() 22 } 23 ``` 24 25 26 27 28 29 ## todo 30 31 当前生成的上一个数字形式的全局id,以后待补充一个UUID 32 33 实现UUID可参考https://github.com/google/uuid 34 35 北京时间2021年10月08日00:06:42,UUID暂时不考虑做入这个包内,也许会直接使用Google的包 36 37 ## ref. Copied from houzhenkai