aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-02-16 21:28:33 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-02-16 21:28:33 +0800
commit702218008ee2b6d708d6b2821cdef80736bb3224 (patch)
treed55ff7ce88187082378e7d8e4c2f3aad14d23b4e /Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go
parent202362d9258335c695eb75f55f4be74a50a1af33 (diff)
downloaddexon-702218008ee2b6d708d6b2821cdef80736bb3224.tar
dexon-702218008ee2b6d708d6b2821cdef80736bb3224.tar.gz
dexon-702218008ee2b6d708d6b2821cdef80736bb3224.tar.bz2
dexon-702218008ee2b6d708d6b2821cdef80736bb3224.tar.lz
dexon-702218008ee2b6d708d6b2821cdef80736bb3224.tar.xz
dexon-702218008ee2b6d708d6b2821cdef80736bb3224.tar.zst
dexon-702218008ee2b6d708d6b2821cdef80736bb3224.zip
Add versioned dependencies from godep
Diffstat (limited to 'Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go')
-rw-r--r--Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go b/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go
new file mode 100644
index 000000000..63580044b
--- /dev/null
+++ b/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go
@@ -0,0 +1,41 @@
+// Copyright 2011 Google Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package uuid
+
+import (
+ "encoding/binary"
+)
+
+// NewUUID returns a Version 1 UUID based on the current NodeID and clock
+// sequence, and the current time. If the NodeID has not been set by SetNodeID
+// or SetNodeInterface then it will be set automatically. If the NodeID cannot
+// be set NewUUID returns nil. If clock sequence has not been set by
+// SetClockSequence then it will be set automatically. If GetTime fails to
+// return the current NewUUID returns nil.
+func NewUUID() UUID {
+ if nodeID == nil {
+ SetNodeInterface("")
+ }
+
+ now, err := GetTime()
+ if err != nil {
+ return nil
+ }
+
+ uuid := make([]byte, 16)
+
+ time_low := uint32(now & 0xffffffff)
+ time_mid := uint16((now >> 32) & 0xffff)
+ time_hi := uint16((now >> 48) & 0x0fff)
+ time_hi |= 0x1000 // Version 1
+
+ binary.BigEndian.PutUint32(uuid[0:], time_low)
+ binary.BigEndian.PutUint16(uuid[4:], time_mid)
+ binary.BigEndian.PutUint16(uuid[6:], time_hi)
+ binary.BigEndian.PutUint16(uuid[8:], clock_seq)
+ copy(uuid[10:], nodeID)
+
+ return uuid
+}