Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // NIL is defined in RFC 4122 section 4.1.7. // The nil UUID is special form of UUID that is specified to have all 128 bits set to zero. NIL = &UUID{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } )
Functions ¶
func GetUUID8Byte ¶
func NewUUID ¶
func NewUUID() string
func TestNewV5(t *testing.T) {
namespace := NewNamespaceUUID("test")
uuid := NewV5(namespace, []byte("test name"))
if uuid.Version() != 5 {
t.Errorf("invalid version %d - expected 5", uuid.Version())
}
t.Logf("UUID V5: %s", uuid)
}
// NewV4 creates a new UUID with variant 4 as described in RFC 4122. // Variant 4 based on pure random bytes.
func NewV4() *UUID {
buf := make([]byte, 16)
rand.Read(buf)
buf[6] = (buf[6] & 0x0f) | 0x40
var uuid UUID
copy(uuid[:], buf[:])
uuid.variantRFC4122()
return &uuid
}
/*
func TestNewV4(t *testing.T) {
uuid := NewV4()
if uuid.Version() != 4 {
t.Errorf("invalid version %d - expected 4", uuid.Version())
}
t.Logf("UUID V4: %s", uuid)
}
// NewV3 creates a new UUID with variant 3 as described in RFC 4122. // Variant 3 based namespace-uuid and name and MD-5 hash calculation.
func NewV3(namespace *UUID, name []byte) *UUID {
uuid := newByHash(md5.New(), namespace, name)
uuid[6] = (uuid[6] & 0x0f) | 0x30
return uuid
}
/*
func TestNewV3(t *testing.T) {
namespace := NewNamespaceUUID("test")
uuid := NewV3(namespace, []byte("test name"))
if uuid.Version() != 3 {
t.Errorf("invalid version %d - expected 3", uuid.Version())
}
t.Logf("UUID V3: %s", uuid)
}
NewNamespaceUUID creates a namespace UUID by using the namespace name in the NIL name space. This is a different approach as the 4 "standard" namespace UUIDs which are timebased UUIDs (V1).
func NewNamespaceUUID(namespace string) string {
namespace = time.Now().String()
return NewV5(NIL, []byte(namespace)).String()
}
Types ¶
Click to show internal directories.
Click to hide internal directories.