update uuidv4

Use uuidv4 generate
This commit is contained in:
Trinh Dinh Bien 2017-07-27 11:15:56 +07:00 committed by GitHub
parent a51f5994bb
commit 553a8a732d
1 changed files with 3 additions and 10 deletions

View File

@ -1,23 +1,16 @@
package uid package uid
import ( import (
"crypto/rand"
"encoding/hex" "encoding/hex"
"io" "github.com/satori/go.uuid"
) )
// uid returns a unique id. These ids consist of 128 bits from a // uid returns a v4 unique id. These ids consist of 128 bits from a
// cryptographically strong pseudo-random generator and are like uuids, but // cryptographically strong pseudo-random generator and are like uuids, but
// without the dashes and significant bits. // without the dashes and significant bits.
// //
// See: http://en.wikipedia.org/wiki/UUID#Random_UUID_probability_of_duplicates // See: http://en.wikipedia.org/wiki/UUID#Random_UUID_probability_of_duplicates
func Uid() string { func Uid() string {
id := make([]byte, 16) id := uuid.NewV1().Bytes()
_, err := io.ReadFull(rand.Reader, id)
if err != nil {
// This is probably an appropriate way to handle errors from our source
// for random bits.
panic(err)
}
return hex.EncodeToString(id) return hex.EncodeToString(id)
} }