summaryrefslogtreecommitdiff
path: root/proto/id.go
diff options
context:
space:
mode:
Diffstat (limited to 'proto/id.go')
-rw-r--r--proto/id.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/proto/id.go b/proto/id.go
new file mode 100644
index 0000000..22bb395
--- /dev/null
+++ b/proto/id.go
@@ -0,0 +1,28 @@
+package proto
+
+import (
+ "time"
+ "strconv"
+)
+
+var counter = make(chan uint8)
+func init() {
+ go func() {
+ var i uint8
+ for i = 0; true; i++ {
+ counter <- i
+ }
+ }()
+}
+
+var epoch = time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
+
+func GenId() string {
+ t := time.Now().UnixMilli() - epoch.UnixMilli()
+ id := uint64(t << 6) | uint64(<-counter & 63)
+ return strconv.FormatUint(id, 36)
+}
+
+func Timestamp() string {
+ return strconv.FormatInt(time.Now().Unix(), 10)
+}