diff options
author | Jeff R. Allen <jra@nella.org> | 2015-09-10 23:48:20 +0800 |
---|---|---|
committer | Jeff R. Allen <jra@nella.org> | 2015-09-12 18:49:24 +0800 |
commit | 0d4072777520a665637937efd440e06f18ea0626 (patch) | |
tree | c6814091d82cafaae5d6ec192e174493f8d8d6af /Godeps/_workspace/src/github.com/pborman/uuid/version1.go | |
parent | 90f1fe0ed2399f90f01c09e61e244121ef7d148a (diff) | |
download | go-tangerine-0d4072777520a665637937efd440e06f18ea0626.tar.gz go-tangerine-0d4072777520a665637937efd440e06f18ea0626.tar.zst go-tangerine-0d4072777520a665637937efd440e06f18ea0626.zip |
Change go-uuid to use the current supported repository.
Diffstat (limited to 'Godeps/_workspace/src/github.com/pborman/uuid/version1.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/version1.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/pborman/uuid/version1.go b/Godeps/_workspace/src/github.com/pborman/uuid/version1.go new file mode 100644 index 000000000..0127eacfa --- /dev/null +++ b/Godeps/_workspace/src/github.com/pborman/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, seq, 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:], seq) + copy(uuid[10:], nodeID) + + return uuid +} |