internal/chat: мультиканальный Router (UserID-сессии, routing, pending Ask/ответ) + Channel интерфейс
All checks were successful
build-test / build (push) Successful in 41s
All checks were successful
build-test / build (push) Successful in 41s
This commit is contained in:
18
internal/chat/questionid.go
Normal file
18
internal/chat/questionid.go
Normal file
@@ -0,0 +1,18 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user