github.com/aatuh/randutil/uuid.
A tiny Go helper for RFC 4122 UUID Version 4 (random) with Variant 1. Provides secure generation, parsing/validation, and a zero UUID helper.
Import the package; go get will resolve the module automatically:
// DEPRECATED: Use github.com/aatuh/randutil/uuid instead
import "github.com/aatuh/uuid"u, err := uuid.Ver4Var1()
if err != nil { /* handle */ }
fmt.Println(u.String())
u2 := uuid.MustVer4Var1()
fmt.Println(u2)u, err := uuid.Ver4Var1FromString("6f1a0b1c-8d7e-4a2b-8c9d-1e2f3a4b5c6d")
if err != nil { /* invalid */ }
if uuid.IsValid("not-a-uuid") {
// never reached
}Returns a value of canonical zero UUID with v4/variant bits set:
z := uuid.Zero()
fmt.Println(z.String())
// 00000000-0000-4000-8000-000000000000type UUID stringVer4Var1() (UUID, error)MustVer4Var1() UUIDVer4Var1FromString(s string) (UUID, error)MustVer4Var1FromString(s string) *UUIDZero() *UUIDIsValid(s string) bool
- Output format is
8-4-4-4-12hex with the third block starting with4(version 4) and the fourth block starting with one of8,9,A,B(variant 1). - Uses
crypto/randfor variant selection and secure hex generation.
This package is deprecated. Please migrate to github.com/aatuh/randutil/uuid:
// Old
import "github.com/aatuh/uuid"
// New
import "github.com/aatuh/randutil/uuid"The API is compatible, so you can simply update your import statement.