diff options
author | Duco van Amstel <helcaraxan@gmail.com> | 2018-11-18 17:55:05 +0000 |
---|---|---|
committer | Wim <wim@42.be> | 2018-11-25 21:21:04 +0100 |
commit | 09875fe1603307080f3a4172985c5dca3bd9912d (patch) | |
tree | a23220772f6f6597d509ca71b2df3480a77b8076 /vendor/github.com/rs/xid/id.go | |
parent | f716b8fc0ff90f47b61e218ef34019b38bd70e0d (diff) | |
download | matterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.tar.gz matterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.tar.bz2 matterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.zip |
Update direct dependencies where possible
Diffstat (limited to 'vendor/github.com/rs/xid/id.go')
-rw-r--r-- | vendor/github.com/rs/xid/id.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/vendor/github.com/rs/xid/id.go b/vendor/github.com/rs/xid/id.go index 51b8d7fa..466faf26 100644 --- a/vendor/github.com/rs/xid/id.go +++ b/vendor/github.com/rs/xid/id.go @@ -42,6 +42,7 @@ package xid import ( + "bytes" "crypto/md5" "crypto/rand" "database/sql/driver" @@ -51,10 +52,9 @@ import ( "hash/crc32" "io/ioutil" "os" + "sort" "sync/atomic" "time" - "bytes" - "sort" ) // Code inspired from mgo/bson ObjectId @@ -143,9 +143,14 @@ func randInt() uint32 { // New generates a globally unique ID func New() ID { + return NewWithTime(time.Now()) +} + +// NewWithTime generates a globally unique ID with the passed in time +func NewWithTime(t time.Time) ID { var id ID // Timestamp, 4 bytes, big endian - binary.BigEndian.PutUint32(id[:], uint32(time.Now().Unix())) + binary.BigEndian.PutUint32(id[:], uint32(t.Unix())) // Machine, first 3 bytes of md5(hostname) id[4] = machineID[0] id[5] = machineID[1] @@ -339,7 +344,6 @@ func (id ID) Compare(other ID) int { return bytes.Compare(id[:], other[:]) } - type sorter []ID func (s sorter) Len() int { |