MCPcopy
hub / github.com/google/uuid / NewUUID

Function NewUUID

version1.go:19–44  ·  view source on GitHub ↗

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 SetClock

()

Source from the content-addressed store, hash-verified

17//
18// In most cases, New should be used.
19func NewUUID() (UUID, error) {
20 var uuid UUID
21 now, seq, err := GetTime()
22 if err != nil {
23 return uuid, err
24 }
25
26 timeLow := uint32(now & 0xffffffff)
27 timeMid := uint16((now >> 32) & 0xffff)
28 timeHi := uint16((now >> 48) & 0x0fff)
29 timeHi |= 0x1000 // Version 1
30
31 binary.BigEndian.PutUint32(uuid[0:], timeLow)
32 binary.BigEndian.PutUint16(uuid[4:], timeMid)
33 binary.BigEndian.PutUint16(uuid[6:], timeHi)
34 binary.BigEndian.PutUint16(uuid[8:], seq)
35
36 nodeMu.Lock()
37 if nodeID == zeroID {
38 setNodeInterface("")
39 }
40 copy(uuid[10:], nodeID[:])
41 nodeMu.Unlock()
42
43 return uuid, nil
44}

Callers 4

NewDCESecurityFunction · 0.85
TestClockSeqRaceFunction · 0.85
TestClockSeqFunction · 0.85
TestVersion1Function · 0.85

Calls 2

GetTimeFunction · 0.85
setNodeInterfaceFunction · 0.85

Tested by 3

TestClockSeqRaceFunction · 0.68
TestClockSeqFunction · 0.68
TestVersion1Function · 0.68