Created
March 13, 2017 22:45
-
-
Save Adron/b8864c5e0d652f8ca14eb154e806a3bd to your computer and use it in GitHub Desktop.
UUID v1, v2, v3, v4 and v5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/satori/go.uuid" | |
) | |
func main() { | |
// Creating UUID Version 1 | |
uuid1 := uuid.NewV1() | |
fmt.Printf("UUIDv1: %s\n", uuid1) | |
// Creating UUID Version 2 - Domain Person | |
uuid2 := uuid.NewV2(uuid.DomainPerson) | |
fmt.Printf("UUIDv2: %s\n", uuid2) | |
// Creating UUID Version 2 - Domain Group | |
uuid2b := uuid.NewV2(uuid.DomainGroup) | |
fmt.Printf("UUIDv2: %s\n", uuid2b) | |
// Creating UUID Version 2 - Domain Organization | |
uuid2c := uuid.NewV2(uuid.DomainOrg) | |
fmt.Printf("UUIDv2: %s\n", uuid2c) | |
// Creating UUID Version 3 | |
uuid3 := uuid.NewV3(uuid.NamespaceDNS, "someplace.org") | |
fmt.Printf("UUIDv2: %s\n", uuid3) | |
// Creating UUID Version 4 | |
uuid4 := uuid.NewV4() | |
fmt.Printf("UUIDv4: %s\n", uuid4) | |
// Creating UUID Version 5 | |
uuid5 := uuid.NewV5(uuid.NamespaceURL, "blaghdblagh.com") | |
fmt.Printf("UUIDv5: %s\n", uuid5) | |
// Parsing UUID from string input | |
u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8") | |
if err != nil { | |
fmt.Printf("Something gone wrong: %s", err) | |
} | |
fmt.Printf("Successfully parsed: %s\n", u2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment