-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuuid-example.go
61 lines (48 loc) · 1.49 KB
/
uuid-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
package main
import (
"fmt"
"github.com/satori/go.uuid"
)
func main() {
// Creating UUID Version 1
uuidstr1, err := uuid.NewV1()
if err != nil {
fmt.Printf("Something went wrong: %s", err)
return
}
fmt.Printf("UUIDv1: %s\n", uuidstr1)
// Creating UUID Version 2
// uuid.DomainPerson
// uuid.DomainGroup
uuidstr2, err := uuid.NewV2(uuid.DomainGroup)
if err != nil {
fmt.Printf("Something went wrong: %s", err)
return
}
fmt.Printf("UUIDv2: %s\n", uuidstr2)
// Creating UUID Version 3
uuidstr3 := uuid.NewV3(uuid.NamespaceDNS, "google.com")
fmt.Printf("UUIDv3-DNS: %s\n", uuidstr3)
uuidstr3 = uuid.NewV3(uuid.NamespaceURL, "google.com")
fmt.Printf("UUIDv3-URL: %s\n", uuidstr3)
uuidstr3 = uuid.NewV3(uuid.NamespaceOID, "Hello World!")
fmt.Printf("UUIDv3-OID: %s\n", uuidstr3)
uuidstr3 = uuid.NewV3(uuid.NamespaceX500, "Hello World!")
fmt.Printf("UUIDv3-X500: %s\n", uuidstr3)
// Creating UUID Version 4
uuidstr4, err := uuid.NewV4()
if err != nil {
fmt.Printf("Something went wrong: %s", err)
return
}
fmt.Printf("UUIDv4: %s\n", uuidstr4)
// Creating UUID Version 5
uuidstr5 := uuid.NewV5(uuid.NamespaceDNS, "google.com")
fmt.Printf("UUIDv5-DNS: %s\n", uuidstr5)
uuidstr5 = uuid.NewV5(uuid.NamespaceURL, "google.com")
fmt.Printf("UUIDv5-URL: %s\n", uuidstr5)
uuidstr5 = uuid.NewV5(uuid.NamespaceOID, "Hello World!")
fmt.Printf("UUIDv5-OID: %s\n", uuidstr5)
uuidstr5 = uuid.NewV5(uuid.NamespaceX500, "Hello World!")
fmt.Printf("UUIDv5-X500: %s\n", uuidstr5)
}