diff options
| author | citrons <citrons@mondecitronne.com> | 2025-01-26 01:56:53 -0600 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-01-26 01:56:53 -0600 |
| commit | 10b8a79389e7073f6bd65695c3d05c77b825bc33 (patch) | |
| tree | b7e6dbd84b5b2c960ab8aafc1f99c3950d679e44 /proto/id.go | |
initial commit
Diffstat (limited to 'proto/id.go')
| -rw-r--r-- | proto/id.go | 28 |
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) +} |
