1
0
mirror of https://github.com/google/uuid.git synced 2025-09-16 09:16:30 +02:00

Bring naming of exported values inline with current Go practice.

This commit is contained in:
Paul Borman
2016-02-29 06:04:36 -08:00
parent 386477fd90
commit 834b00a6a5
5 changed files with 15 additions and 16 deletions

4
dce.go
View File

@@ -61,9 +61,9 @@ func (uuid UUID) Domain() Domain {
return Domain(uuid[9])
}
// Id returns the id for a Version 2 UUID. Ids are only defined for Vrsion 2
// ID returns the id for a Version 2 UUID. Ids are only defined for Version 2
// UUIDs.
func (uuid UUID) Id() uint32 {
func (uuid UUID) ID() uint32 {
return binary.BigEndian.Uint32(uuid[0:4])
}

10
hash.go
View File

@@ -12,11 +12,11 @@ import (
// Well known namespace IDs and UUIDs
var (
NameSpace_DNS = Must(Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8"))
NameSpace_URL = Must(Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8"))
NameSpace_OID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
NameSpace_X500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
NIL UUID // empty UUID, all zeros
NameSpaceDNS = Must(Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8"))
NameSpaceURL = Must(Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8"))
NameSpaceOID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
NameSpaceX500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
Nil UUID // empty UUID, all zeros
)
// NewHash returns a new UUID derived from the hash of space concatenated with

View File

@@ -20,7 +20,7 @@ func (u UUID) MarshalText() ([]byte, error) {
func (u *UUID) UnmarshalText(data []byte) error {
// See comment in ParseBytes why we do this.
// id, err := ParseBytes(data)
id, err := Parse(*(*string)(unsafe.Pointer(&data)))
id, err := Parse(*(*string)(unsafe.Pointer(&data)))
if err == nil {
*u = id
}

View File

@@ -353,7 +353,7 @@ func TestNodeAndTime(t *testing.T) {
}
func TestMD5(t *testing.T) {
uuid := NewMD5(NameSpace_DNS, []byte("python.org")).String()
uuid := NewMD5(NameSpaceDNS, []byte("python.org")).String()
want := "6fa459ea-ee8a-3ca4-894e-db77e160355e"
if uuid != want {
t.Errorf("MD5: got %q expected %q", uuid, want)
@@ -361,7 +361,7 @@ func TestMD5(t *testing.T) {
}
func TestSHA1(t *testing.T) {
uuid := NewSHA1(NameSpace_DNS, []byte("python.org")).String()
uuid := NewSHA1(NameSpaceDNS, []byte("python.org")).String()
want := "886313e1-3b8a-5372-9b90-0c9aee199e5d"
if uuid != want {
t.Errorf("SHA1: got %q expected %q", uuid, want)
@@ -407,7 +407,7 @@ func testDCE(t *testing.T, name string, uuid UUID, err error, domain Domain, id
if v := uuid.Domain(); v != domain {
t.Errorf("%s: %s: expected domain %d, got %d", name, uuid, domain, v)
}
if v := uuid.Id(); v != id {
if v := uuid.ID(); v != id {
t.Errorf("%s: %s: expected id %d, got %d", name, uuid, id, v)
}
}
@@ -471,12 +471,11 @@ func parseBytesCopy(b []byte) (UUID, error) {
return Parse(string(b))
}
// xtobb converts the the first two hex bytes of x into a byte.
func xtobb(x []byte) (byte, bool) {
b1 := xvalues[x[0]]
b2 := xvalues[x[1]]
return (b1 << 4) | b2, b1 != 255 && b2 != 255
b1 := xvalues[x[0]]
b2 := xvalues[x[1]]
return (b1 << 4) | b2, b1 != 255 && b2 != 255
}
// parseBytes is the same as Parse, but with byte slices. It demonstrates

View File

@@ -30,7 +30,7 @@ func NewRandom() (UUID, error) {
var uuid UUID
_, err := io.ReadFull(rander, uuid[:])
if err != nil {
return NIL, err
return Nil, err
}
uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10