summaryrefslogtreecommitdiff
path: root/proto/id.go
blob: ae7471805d128476117079a67e318c3ae84f75b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package proto

import (
	"time"
	"strconv"
	"sync/atomic"
)

var counter atomic.Uint32
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.Load() & 63)
	counter.Add(1)
	return strconv.FormatUint(id, 36)
}

func Timestamp() string {
	return strconv.FormatInt(time.Now().Unix(), 10)
}