Files
byre/internal/ids/ids.go
T

47 lines
1.1 KiB
Go
Raw Normal View History

package ids
import (
"crypto/rand"
)
const (
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
randomLength = 11
)
2026-10-21 09:05:33 -07:00
type Prefix string
const (
2026-10-21 09:05:33 -07:00
Project Prefix = "prj"
Task Prefix = "tsk"
Session Prefix = "ses"
Snapshot Prefix = "snp"
Review Prefix = "rev"
InboxItem Prefix = "inb"
InboxResponse Prefix = "rsp"
Blob Prefix = "blb"
LeadNote Prefix = "not"
WorkflowDefinition Prefix = "wfd"
Send Prefix = "snd"
Client Prefix = "cli"
ClientRequest Prefix = "req"
Transfer Prefix = "xfr"
Terminal Prefix = "trm"
SavedCommand Prefix = "cmd"
Schedule Prefix = "sch"
)
2026-10-21 09:05:33 -07:00
func New(prefix Prefix) string {
out := make([]byte, randomLength)
buf := make([]byte, 1)
for i := 0; i < len(out); {
rand.Read(buf)
if int(buf[0]) >= 256/len(alphabet)*len(alphabet) {
continue
}
out[i] = alphabet[int(buf[0])%len(alphabet)]
i++
}
2026-10-21 09:05:33 -07:00
return string(prefix) + string(out)
}