feat: 新增 snowid(雪花ID+GORM钩子模板,吸收go-hua); wsc新增SessionClient会话层(吸收两端internal/cloud); jwtx重写为标准三段式HS256+密钥显式传参

This commit is contained in:
w11
2026-09-19 21:12:44 +08:00
parent 9ef71f51d4
commit 83679e2080
8 changed files with 452 additions and 42 deletions
+27
View File
@@ -0,0 +1,27 @@
# snowid
基于 `bwmarrin/snowflake` 的雪花 ID 生成器(进程内单例)+ GORM 模型 ID 钩子模板。
## 用法
```go
import "git.zeroonesoft.cn/golib/zogo/snowid"
func main() {
if err := snowid.Init(1); err != nil { ... } // 节点ID 0-1023
id := snowid.Generate() // int64
s := snowid.GenerateString() // string
}
// 生成模型(gorm.io/gen):让 bigint 主键自动填充
// gen-model 脚本里:
opts = append(opts, gen.WithMethod(snowid.IDMethod{}))
// 生成的模型自带 BeforeCreate:Id==0 时填 snowid.Generate()
```
## 注意
- **必须先 Init 再 Generate**,否则 panic(启动期暴露,不留隐患)。
- `InitWithStartTime` 会改全局 Epoch,须在进程首个 NewNode 前调用;同一部署里
各服务的 Epoch 口径要一致,ID 才可排序比较。
- 多实例部署时节点 ID 不得重复,否则会生成重复 ID。