mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
9f8890d159
- Declared module Wavelet in backend/go.mod - Replaced github.com/Rain-kl/Wavelet/ with clean Wavelet/ import paths across backend codebase - Updated architecture guards, Makefile, swagger, and build tests - 100% passed all tests, lint checks, and binary compilation
29 lines
676 B
Go
29 lines
676 B
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package util
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"io"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// uniqueIDBytes 生成唯一 ID 所需的随机字节长度
|
|
const uniqueIDBytes = 32
|
|
|
|
// GenerateUniqueIDSimple 生成 64 位唯一标识符
|
|
func GenerateUniqueIDSimple() string {
|
|
randomBytes := make([]byte, uniqueIDBytes)
|
|
if _, err := io.ReadFull(rand.Reader, randomBytes); err != nil {
|
|
// 如果随机数生成失败,使用 UUID 作为后备
|
|
uuidBytes := []byte(uuid.NewString())
|
|
hash := sha256.Sum256(uuidBytes)
|
|
copy(randomBytes, hash[:])
|
|
}
|
|
return hex.EncodeToString(randomBytes)
|
|
}
|