Compare commits

..

5 Commits
v1.0.5 ... main

Author SHA1 Message Date
AI Engineer
fce7a49a27 chore: infrastructure alignment and doc sync (by AICoder) 2026-05-16 01:21:58 +08:00
AI Engineer
fddabe4e98 对齐 Tag v1.3.0 (By AI) 2026-05-10 15:48:30 +08:00
AI Engineer
dc1a3cb434 chore: infrastructure alignment 2026-05-10 13:08:51 +08:00
AI Engineer
9bd449f1fc chore: infrastructure alignment 2026-05-10 12:53:09 +08:00
AI Engineer
4497e9312a feat: introduce semantic ID generation and IDMaker SOP alignment (by AI) 2026-05-10 10:49:58 +08:00
5 changed files with 70 additions and 16 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.ai/
.geminiignore
.gemini
/CODE-FULL.md

View File

@ -25,25 +25,31 @@ ID 结构由 `secTag` (1位) + `sec` (5-6位) + `secIndex` (1-5位) + `padding`
## API Reference ## API Reference
### 核心生成器 ### 核心生成器
- `func NewIdMaker(incr func(sec uint64) uint64) *IdMaker`:创建自定义步长的 ID 生成器。 - `func NewIDMaker(incr func(sec uint64) uint64) *IDMaker`:创建自定义步长的 ID 生成器。
- `var DefaultIdMaker`:默认全局 ID 生成器(单机模式)。 - `var DefaultIDMaker`:默认全局 ID 生成器(单机模式)。
### 格式化生成 (推荐作为 PK) ### 格式化生成 (语义化方法推荐)
- `func MakeId(size int) string`DefaultIdMaker.Get(size) 的别名。 - `func (im *IDMaker) Get8Bytes4KPerSecond() string`8 位长度,并发上限 3,844/s。
- `func (im *IdMaker) Get(size int) string`生成随机唯一ID。 - `func (im *IDMaker) Get9Bytes90KPerSecond() string`9 位长度,并发上限 9 万/s。
- `func (im *IdMaker) GetForMysql(size int) string`MySQL 优化版,自动右旋散列,解决写入热点。 - `func (im *IDMaker) Get10Bytes14MPerSecond() string`10 位长度,并发上限 1,477 万/s。
- `func (im *IdMaker) GetForPostgreSQL(size int) string`PostgreSQL 优化版,保持时间局部单调。 - `func (im *IDMaker) Get11Bytes900MPerSecond() string`11 位长度,并发上限 9 亿/s。
- `func (im *IDMaker) Get12BytesUltraPerSecond() string`12 位长度,支持超越 9 亿并发。
### 数据库专用生成 (推荐作为 PK)
- `func (im *IDMaker) Get(size int) string`生成指定长度的随机唯一ID。
- `func (im *IDMaker) GetForMysql(size int) string`MySQL 优化版,自动右旋散列,解决写入热点。
- `func (im *IDMaker) GetForPostgreSQL(size int) string`PostgreSQL 优化版,保持时间局部单调。
## 快速开始 ## 快速开始
```go ```go
import "apigo.cc/go/id" import "apigo.cc/go/id"
// 生成一个 12 位长度的唯一ID // 语义化生成示例 (推荐)
newID := id.MakeId(12) requestId := id.Get10Bytes14MPerSecond()
// 生成一个 10 位长度的 MySQL 友好主键 // 数据库主键生成示例
newID := id.DefaultIdMaker.GetForMysql(10) userId := id.DefaultIDMaker.GetForMysql(10)
``` ```
## 分布式集群扩展示例 ## 分布式集群扩展示例

8
go.mod
View File

@ -3,10 +3,8 @@ module apigo.cc/go/id
go 1.25.0 go 1.25.0
require ( require (
apigo.cc/go/encoding v1.0.5 apigo.cc/go/encoding v1.3.1
apigo.cc/go/rand v1.0.5 apigo.cc/go/rand v1.3.1
) )
replace apigo.cc/go/encoding => ../encoding require apigo.cc/go/cast v1.3.3 // indirect
replace apigo.cc/go/rand => ../rand

6
go.sum
View File

@ -0,0 +1,6 @@
apigo.cc/go/cast v1.3.3 h1:aln5eDR5DZVWVzZ/y5SJh1gQNgWv2sT82I25NaO9g34=
apigo.cc/go/cast v1.3.3/go.mod h1:lGlwImiOvHxG7buyMWhFzcdvQzmSaoKbmr7bcDfUpHk=
apigo.cc/go/encoding v1.3.1 h1:y8O58KYAyulkThg1O2ji2BqjnFoSvk42sit9I3z+K7Y=
apigo.cc/go/encoding v1.3.1/go.mod h1:xAJk5b83VZ31mXMTnyp0dfMoBKfT/AHDn0u+cQfojgY=
apigo.cc/go/rand v1.3.1 h1:7FvsI6PtQ5XrWER0dTiLVo0p7GIxRidT/TBKhVy93j8=
apigo.cc/go/rand v1.3.1/go.mod h1:mZ/4Soa3bk+XvDaqPWJuUe1bfEi4eThBj1XmEAuYxsk=

40
id.go
View File

@ -103,6 +103,26 @@ func (im *IDMaker) Get(size int) string {
return im.get(size, false, false) return im.get(size, false, false)
} }
func (im *IDMaker) Get8Bytes4KPerSecond() string {
return im.get(8, false, false)
}
func (im *IDMaker) Get9Bytes90KPerSecond() string {
return im.get(9, false, false)
}
func (im *IDMaker) Get10Bytes14MPerSecond() string {
return im.get(10, false, false)
}
func (im *IDMaker) Get11Bytes900MPerSecond() string {
return im.get(11, false, false)
}
func (im *IDMaker) Get12BytesUltraPerSecond() string {
return im.get(12, false, false)
}
func (im *IDMaker) GetForMysql(size int) string { func (im *IDMaker) GetForMysql(size int) string {
return im.get(size, true, true) return im.get(size, true, true)
} }
@ -110,3 +130,23 @@ func (im *IDMaker) GetForMysql(size int) string {
func (im *IDMaker) GetForPostgreSQL(size int) string { func (im *IDMaker) GetForPostgreSQL(size int) string {
return im.get(size, true, false) return im.get(size, true, false)
} }
func Get8Bytes4KPerSecond() string {
return DefaultIDMaker.Get8Bytes4KPerSecond()
}
func Get9Bytes90KPerSecond() string {
return DefaultIDMaker.Get9Bytes90KPerSecond()
}
func Get10Bytes14MPerSecond() string {
return DefaultIDMaker.Get10Bytes14MPerSecond()
}
func Get11Bytes900MPerSecond() string {
return DefaultIDMaker.Get11Bytes900MPerSecond()
}
func Get12BytesUltraPerSecond() string {
return DefaultIDMaker.Get12BytesUltraPerSecond()
}