Files
ratatoskr-go/internal/chat/questionid.go
2026-08-14 20:33:04 +05:00

19 lines
628 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package chat
import (
"crypto/rand"
"encoding/hex"
"time"
)
// newQuestionID генерирует уникальный идентификатор вопроса (блок 4:
// идентификатор в каждом Message, чтобы связать ответ с вопросом).
func newQuestionID() string {
b := make([]byte, 8)
if _, err := rand.Read(b); err != nil {
// крипто-rand недоступен — fallback по времени (уникален на практике)
return "q_" + hex.EncodeToString([]byte(time.Now().Format("150405.000000000")))
}
return "q_" + hex.EncodeToString(b)
}