From 10b8a79389e7073f6bd65695c3d05c77b825bc33 Mon Sep 17 00:00:00 2001 From: citrons Date: Sun, 26 Jan 2025 01:56:53 -0600 Subject: initial commit --- proto/id.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 proto/id.go (limited to 'proto/id.go') 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) +} -- cgit v1.2.3