summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/packer/common/uuid/uuid.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mitchellh/packer/common/uuid/uuid.go')
-rw-r--r--vendor/github.com/mitchellh/packer/common/uuid/uuid.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/packer/common/uuid/uuid.go b/vendor/github.com/mitchellh/packer/common/uuid/uuid.go
new file mode 100644
index 00000000..d8b9830b
--- /dev/null
+++ b/vendor/github.com/mitchellh/packer/common/uuid/uuid.go
@@ -0,0 +1,24 @@
+package uuid
+
+import (
+ "crypto/rand"
+ "fmt"
+ "time"
+)
+
+// Generates a time ordered UUID. Top 32 bits are a timestamp,
+// bottom 96 are random.
+func TimeOrderedUUID() string {
+ unix := uint32(time.Now().UTC().Unix())
+
+ b := make([]byte, 12)
+ n, err := rand.Read(b)
+ if n != len(b) {
+ err = fmt.Errorf("Not enough entropy available")
+ }
+ if err != nil {
+ panic(err)
+ }
+ return fmt.Sprintf("%08x-%04x-%04x-%04x-%04x%08x",
+ unix, b[0:2], b[2:4], b[4:6], b[6:8], b[8:])
+}