-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.go
More file actions
44 lines (33 loc) · 798 Bytes
/
generator.go
File metadata and controls
44 lines (33 loc) · 798 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright Chrono Technologies LLC
// SPDX-License-Identifier: MIT
package main
import (
"time"
"github.com/google/uuid"
)
func generateUUIDV4() (uuid.UUID, error) {
return uuid.NewRandom()
}
func generateUUIDV7(customTime string) (uuid.UUID, error) {
var err error
var ret uuid.UUID
var timestamp time.Time
if ret, err = uuid.NewV7(); err != nil {
return uuid.UUID{}, err
}
if len(customTime) == 0 {
return ret, nil
}
if timestamp, err = parseTimeInput(customTime); err != nil {
return uuid.UUID{}, err
}
// replace the first 6-bytes with the custom timestamp
msec := timestamp.UnixMilli()
ret[0] = byte(msec >> 40)
ret[1] = byte(msec >> 32)
ret[2] = byte(msec >> 24)
ret[3] = byte(msec >> 16)
ret[4] = byte(msec >> 8)
ret[5] = byte(msec)
return ret, nil
}