package generate import ( "crypto/rand" "encoding/hex" "log" "strings" ) func id(prefix string, length int) string { var id [16]byte var buffer [32]byte builder := strings.Builder{} builder.Grow(length + 31) builder.WriteString(prefix) for builder.Len() < length { _, err := rand.Read(id[:]) if err != nil { log.Panicln("generate.id: failed to use OS random:", err) } hex.Encode(buffer[:], id[:]) builder.Write(buffer[:]) } return builder.String()[:length] } func GroupID() string { return id("G", 16) } func ItemID() string { return id("I", 16) } func ProjectID() string { return id("P", 16) } func ProjectGroupID() string { return id("C", 16) } func TaskID() string { return id("T", 16) } func LogID() string { return id("L", 16) } func GoalID() string { return id("A", 16) }