blob: 9cb092eefc9ef72e0941a6ab7ef0ab0efc89f3a4 (
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
|
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)
var result string
for _, c := range strconv.FormatUint(id, 36) {
result = string(c) + result
}
return result
}
func Timestamp() string {
return strconv.FormatInt(time.Now().Unix(), 10)
}
|