-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
125 lines (109 loc) · 2.49 KB
/
Copy pathexample_test.go
File metadata and controls
125 lines (109 loc) · 2.49 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package uuid_test
import (
"fmt"
"slices"
"github.com/pscheid92/uuid"
)
func ExampleNewV4() {
id := uuid.NewV4()
fmt.Println(id.Version())
// Output: V4
}
func ExampleNewV5() {
id := uuid.NewV5(uuid.NamespaceDNS, "www.example.com")
fmt.Println(id)
// Output: 2ed6657d-e927-568b-95e1-2665a8aea6a2
}
func ExampleNewV7() {
id := uuid.NewV7()
fmt.Println(id.Version())
// Output: V7
}
func ExampleNewV4Batch() {
ids := uuid.NewV4Batch(3)
fmt.Println(len(ids))
fmt.Println(ids[0].Version())
// Output:
// 3
// V4
}
func ExamplePool_NewV4() {
pool := uuid.NewPool()
id := pool.NewV4()
fmt.Println(id.Version())
// Output: V4
}
func ExamplePool_NewV7() {
pool := uuid.NewPool()
id := pool.NewV7()
fmt.Println(id.Version())
// Output: V7
}
func ExampleGenerator_NewV7Batch() {
gen := uuid.NewGenerator()
ids := gen.NewV7Batch(3)
fmt.Println(len(ids))
fmt.Println(ids[0].Version())
// Output:
// 3
// V7
}
func ExampleNewV8() {
var data [16]byte
copy(data[:], "custom-data-here")
id := uuid.NewV8(data)
fmt.Println(id.Version())
// Output: V8
}
func ExampleParse() {
id, err := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
if err != nil {
panic(err)
}
fmt.Println(id)
// Output: 6ba7b810-9dad-11d1-80b4-00c04fd430c8
}
func ExampleParseLenient() {
// Accepts URN, braced, and compact forms in addition to standard
id, err := uuid.ParseLenient("urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8")
if err != nil {
panic(err)
}
fmt.Println(id)
// Output: 6ba7b810-9dad-11d1-80b4-00c04fd430c8
}
func ExampleUUID_URN() {
id := uuid.MustParse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
fmt.Println(id.URN())
// Output: urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8
}
func ExampleCompare() {
ids := []uuid.UUID{
uuid.MustParse("00000000-0000-0000-0000-000000000003"),
uuid.MustParse("00000000-0000-0000-0000-000000000001"),
uuid.MustParse("00000000-0000-0000-0000-000000000002"),
}
slices.SortFunc(ids, uuid.Compare)
for _, id := range ids {
fmt.Println(id)
}
// Output:
// 00000000-0000-0000-0000-000000000001
// 00000000-0000-0000-0000-000000000002
// 00000000-0000-0000-0000-000000000003
}
func ExampleGenerator() {
gen := uuid.NewGenerator()
id := gen.NewV7()
fmt.Println(id.Version())
// Output: V7
}
func ExampleFromBytes() {
b := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
id, err := uuid.FromBytes(b)
if err != nil {
panic(err)
}
fmt.Println(id)
// Output: 6ba7b810-9dad-11d1-80b4-00c04fd430c8
}