summaryrefslogtreecommitdiff
path: root/proto/id.go
blob: 22bb3958a8bccdffbdb67f3d23c20c4d22fd48de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
}