-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
68 lines (49 loc) · 1.4 KB
/
example.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"log"
"github.com/V-H-R-Oliveira/simple-uuid/uuid"
)
func main() {
const customNamespace = "2163d569-2c70-43d4-bb87-ff9c58814ade"
args := make(map[string]string)
args["variant"] = "dce"
uuidv4, err := uuid.NewUUID(4, args)
if err != nil {
log.Fatal("Failed to create an uuidv4 due error:", err)
}
uuidv1, err := uuid.NewUUID(1, args)
if err != nil {
log.Fatal("Failed to create an uuidv1 due error:", err)
}
args["name"] = "test"
args["namespace"] = "dns"
uuidv3, err := uuid.NewUUID(3, args)
if err != nil {
log.Fatal("Failed to create an uuidv3 due error:", err)
}
args["name"] = "foo"
args["namespace"] = "url"
uuidv5, err := uuid.NewUUID(5, args)
if err != nil {
log.Fatal("Failed to create an uuidv5 due error:", err)
}
args["namespace"] = customNamespace
uuidv3CustomNamespace, err := uuid.NewUUID(3, args)
if err != nil {
log.Fatal("Failed to create an uuidv3 with a custom namespace due error:", err)
}
uuidv5CustomNamespace, err := uuid.NewUUID(5, args)
if err != nil {
log.Fatal("Failed to create an uuidv5 with a custom namespace due error:", err)
}
fmt.Printf(
"V1: %s\nV3: %s\nV4: %s\nV5: %s\nV3 with a custom namespace: %s\nV5 with a custom namespace: %s\n",
uuidv1.Stringify(),
uuidv3.Stringify(),
uuidv4.Stringify(),
uuidv5.Stringify(),
uuidv3CustomNamespace.Stringify(),
uuidv5CustomNamespace.Stringify(),
)
}