diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2019-08-08 00:19:33 +0200 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2019-08-08 00:19:33 +0200 |
commit | fde18e485ff7cbc7b2e33dade8e81136f06a5b60 (patch) | |
tree | 79a6dbd13e7e4a46e708a70104c548f403b477ae /vendor/github.com/getlantern/errors/hide.go | |
parent | 93e1de570f47b095905835735dbd67479aa0c2de (diff) |
[pkg] remove vendor
Diffstat (limited to 'vendor/github.com/getlantern/errors/hide.go')
-rw-r--r-- | vendor/github.com/getlantern/errors/hide.go | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/vendor/github.com/getlantern/errors/hide.go b/vendor/github.com/getlantern/errors/hide.go deleted file mode 100644 index f10d863..0000000 --- a/vendor/github.com/getlantern/errors/hide.go +++ /dev/null @@ -1,50 +0,0 @@ -package errors - -import ( - "encoding/binary" - "sync" - - "github.com/getlantern/hidden" -) - -var ( - hiddenErrors = make([]*structured, 100) - nextID = uint64(0) - hiddenMutex sync.RWMutex -) - -// This trick saves the error to a ring buffer and embeds a non-printing -// hiddenID in the error's description, so that if the errors is later wrapped -// by a standard error using something like -// fmt.Errorf("An error occurred: %v", thisError), we can subsequently extract -// the error simply using the hiddenID in the string. -func (e *structured) save() { - hiddenMutex.Lock() - b := make([]byte, 8) - binary.BigEndian.PutUint64(b, nextID) - e.id = nextID - e.hiddenID = hidden.ToString(b) - hiddenErrors[idxForID(nextID)] = e - nextID++ - hiddenMutex.Unlock() -} - -func get(hiddenID []byte) Error { - if len(hiddenID) != 8 { - return nil - } - id := binary.BigEndian.Uint64(hiddenID) - hiddenMutex.RLock() - err := hiddenErrors[idxForID(id)] - hiddenMutex.RUnlock() - if err != nil && err.id == id { - // Found it! - return err - } - // buffer has rolled over - return nil -} - -func idxForID(id uint64) int { - return int(id % uint64(len(hiddenErrors))) -} |