-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathksuid.go
52 lines (41 loc) · 1.3 KB
/
ksuid.go
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
45
46
47
48
49
50
51
52
package uuid
import (
"time"
"github.com/segmentio/ksuid"
)
// NewKSUID generates a new KSUID.
func NewKSUID() ksuid.KSUID {
return ksuid.New()
}
// NewKSUIDRandom generates a new KSUID with now timestamp.
func NewKSUIDRandom() (uid ksuid.KSUID, err error) {
return ksuid.NewRandomWithTime(time.Now())
}
// NewKSUIDRandomWithTime generates a new KSUID with the given timestamp.
func NewKSUIDRandomWithTime(t time.Time) (uid ksuid.KSUID, err error) {
return ksuid.NewRandomWithTime(t)
}
// KSUIDParse decodes a string-encoded representation of a KSUID object.
func KSUIDParse(s string) (ksuid.KSUID, error) {
return ksuid.Parse(s)
}
// KSUIDFromParts constructs a KSUID from constituent parts.
func KSUIDFromParts(t time.Time, payload []byte) (ksuid.KSUID, error) {
return ksuid.FromParts(t, payload)
}
// KSUIDFromBytes constructs a KSUID from a 20-byte binary representation.
func KSUIDFromBytes(b []byte) (ksuid.KSUID, error) {
return ksuid.FromBytes(b)
}
// KSUIDCompare implements comparison for KSUID type.
func KSUIDCompare(a, b ksuid.KSUID) int {
return ksuid.Compare(a, b)
}
// KSUIDSort the given slice of KSUIDs.
func KSUIDSort(ids []ksuid.KSUID) {
ksuid.Sort(ids)
}
// KSUIDIsSorted checks whether a slice of KSUIDs is sorted
func KSUIDIsSorted(ids []ksuid.KSUID) bool {
return ksuid.IsSorted(ids)
}