9
9
> Generation module based on [ Google UUID] ( https://github.com/google/uuid ) .
10
10
11
11
<!-- TOC -->
12
-
13
12
* [ Installation] ( #installation )
14
13
* [ Documentation] ( #documentation )
15
- * [UUID](#uuid)
16
-
14
+ * [ UUID V4 ] ( #uuid-v4 )
15
+ * [ UUID V7 ] ( #uuid-v7 )
17
16
<!-- TOC -->
18
17
19
18
## Installation
@@ -24,11 +23,11 @@ go get github.com/ankorstore/yokai/generate
24
23
25
24
## Documentation
26
25
27
- ### UUID
26
+ ### UUID V4
28
27
29
- This module provides an [ UuidGenerator] ( uuid/generator.go ) interface, allowing to generate UUIDs.
28
+ This module provides an [ UuidGenerator] ( uuid/generator.go ) interface, allowing to generate UUIDs V4 .
30
29
31
- The ` DefaultUuidGenerator ` is based on [ Google UUID] ( https://github.com/google/uuid ) .
30
+ The ` DefaultUuidGenerator ` implementing it is based on [ Google UUID] ( https://github.com/google/uuid ) .
32
31
33
32
``` go
34
33
package main
@@ -70,4 +69,55 @@ func main() {
70
69
generator := uuid.NewDefaultUuidGeneratorFactory ().Create ()
71
70
fmt.Printf (" uuid: %s " , generator.Generate ()) // uuid: dcb5d8b3-4517-4957-a42c-604d11758561
72
71
}
72
+ ```
73
+
74
+ ### UUID V7
75
+
76
+ This module provides an [ UuidV7Generator] ( uuidv7/generator.go ) interface, allowing to generate UUIDs V7.
77
+
78
+ The ` DefaultUuidV7Generator ` implementing it is based on [ Google UUID] ( https://github.com/google/uuid ) .
79
+
80
+ ``` go
81
+ package main
82
+
83
+ import (
84
+ " fmt"
85
+
86
+ " github.com/ankorstore/yokai/generate/uuidv7"
87
+ uuidv7test " github.com/ankorstore/yokai/generate/generatetest/uuidv7"
88
+ )
89
+
90
+ func main () {
91
+ // default UUID V7 generator
92
+ generator := uuidv7.NewDefaultUuidV7Generator ()
93
+ uuid , _ := generator.Generate ()
94
+ fmt.Printf (" uuid: %s " , uuid.String ()) // uuid: 018fdd68-1b41-7eb0-afad-57f45297c7c1
95
+
96
+ // test UUID generator (with deterministic value for testing, requires valid UUID v7)
97
+ testGenerator , _ := uuidv7test.NewTestUuidV7Generator (" 018fdd7d-1576-7a21-900e-1399637bd1a1" )
98
+ uuid, _ = testGenerator.Generate ()
99
+ fmt.Printf (" uuid: %s " , uuid.String ()) // uuid: 018fdd7d-1576-7a21-900e-1399637bd1a1
100
+ }
101
+ ```
102
+
103
+ The module also provides a [ UuidV7GeneratorFactory] ( uuidv7/factory.go ) interface, to create
104
+ the [ UuidV7Generator] ( uuidv7/generator.go ) instances.
105
+
106
+ The ` DefaultUuidV7GeneratorFactory ` generates ` DefaultUuidV7Generator ` instances.
107
+
108
+ ``` go
109
+ package main
110
+
111
+ import (
112
+ " fmt"
113
+
114
+ " github.com/ankorstore/yokai/generate/uuidv7"
115
+ )
116
+
117
+ func main () {
118
+ // default UUID generator factory
119
+ generator := uuidv7.NewDefaultUuidV7GeneratorFactory ().Create ()
120
+ uuid , _ := generator.Generate ()
121
+ fmt.Printf (" uuid: %s " , uuid.String ()) // uuid: 018fdd68-1b41-7eb0-afad-57f45297c7c1
122
+ }
73
123
```
0 commit comments