UUID is a 128 bit (16 byte) Universal Unique Identifier as defined in RFC 4122.
go get github.com/pkg-id/uuid
package main
import "github.com/pkg-id/uuid"
func main() {
v4 := uuid.NewV4Generator(uuid.SecureReader)
uid, err := v4.NewUUID()
if err != nil {
panic(err)
}
println(uid.String())
}
or use StaticReader for testing purposes:
package main
import "github.com/pkg-id/uuid"
func main() {
v4 := uuid.NewV4Generator(uuid.StaticReader)
uid, err := v4.NewUUID()
if err != nil {
panic(err)
}
println(uid.String() == uuid.StaticUUID) // true
}
MIT License. See LICENSE for details.