fix(id): ExchangeInt+HashInt 返回值未被赋值导致 ID 未打乱,修复为 hash 字节编码为 base62 数字(by AI)

Co-Authored-By: deepseek-v4-pro[1m] <deepseek-ai@claude-code-best.win>
This commit is contained in:
AI Engineer 2026-06-21 23:02:54 +08:00
parent 08d2a9f2a3
commit 118609d38d

7
id.go
View File

@ -86,7 +86,12 @@ func (im *IDMaker) get(size int, ordered bool, hashToHead bool) string {
uid = append(uid, inSecIndexBytes...) uid = append(uid, inSecIndexBytes...)
uid = intEncoder.FillInt(uid, size) uid = intEncoder.FillInt(uid, size)
if !ordered { if !ordered {
encoding.HashInt(encoding.ExchangeInt(uid), nil) uid = encoding.ExchangeInt(uid)
hashed := encoding.HashInt(uid, nil)
uid = make([]byte, 0, size)
for i := 0; i < size && i < len(hashed); i++ {
uid = append(uid, intEncoder.EncodeInt(uint64(hashed[i]))[0])
}
} else { } else {
encoding.HashInt(encoding.ExchangeInt(uid[secLen+1:]), nil) encoding.HashInt(encoding.ExchangeInt(uid[secLen+1:]), nil)
if hashToHead { if hashToHead {