From d2eb7e664abb8080b6166681cbeed082c9fbe6eb Mon Sep 17 00:00:00 2001 From: Trinh Dinh Bien Date: Thu, 27 Jul 2017 15:04:59 +0700 Subject: [PATCH] Update Uid() func to v4 Unique id. Reduce Collisions and Standard RFC 4122 --- uid/uid.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/uid/uid.go b/uid/uid.go index 71f0cb3..ec1c5fb 100644 --- a/uid/uid.go +++ b/uid/uid.go @@ -19,5 +19,11 @@ func Uid() string { // for random bits. panic(err) } + // UUID version 4 + id[6] = (id[6] & 0x0f) | (4<<4) + + // SetVariant sets variant bits as described in RFC 4122. + id[8] = (id[8] & 0xbf | 0x80) + return hex.EncodeToString(id) }