diff options
| author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
| commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
| tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/google/uuid/version1.go | |
| parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
| download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip | |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/google/uuid/version1.go')
| -rw-r--r-- | vendor/github.com/google/uuid/version1.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/github.com/google/uuid/version1.go b/vendor/github.com/google/uuid/version1.go new file mode 100644 index 0000000..4631096 --- /dev/null +++ b/vendor/github.com/google/uuid/version1.go | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // Copyright 2016 Google Inc. All rights reserved. | ||
| 2 | // Use of this source code is governed by a BSD-style | ||
| 3 | // license that can be found in the LICENSE file. | ||
| 4 | |||
| 5 | package uuid | ||
| 6 | |||
| 7 | import ( | ||
| 8 | "encoding/binary" | ||
| 9 | ) | ||
| 10 | |||
| 11 | // NewUUID returns a Version 1 UUID based on the current NodeID and clock | ||
| 12 | // sequence, and the current time. If the NodeID has not been set by SetNodeID | ||
| 13 | // or SetNodeInterface then it will be set automatically. If the NodeID cannot | ||
| 14 | // be set NewUUID returns nil. If clock sequence has not been set by | ||
| 15 | // SetClockSequence then it will be set automatically. If GetTime fails to | ||
| 16 | // return the current NewUUID returns nil and an error. | ||
| 17 | // | ||
| 18 | // In most cases, New should be used. | ||
| 19 | func 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 | } | ||