refactor(id): update name to IDLength

pull/10616/head
Chris Goller 2018-10-10 13:57:18 -05:00
parent 21475c22cd
commit b68a98043d
4 changed files with 10 additions and 10 deletions

View File

@ -308,9 +308,9 @@ func bucketIndexKey(b *platform.Bucket) ([]byte, error) {
if err != nil {
return nil, err
}
k := make([]byte, platform.IDStringLength+len(b.Name))
k := make([]byte, platform.IDLength+len(b.Name))
copy(k, orgID)
copy(k[platform.IDStringLength:], []byte(b.Name))
copy(k[platform.IDLength:], []byte(b.Name))
return k, nil
}

10
id.go
View File

@ -7,8 +7,8 @@ import (
"errors"
)
// IDStringLength is the exact length a string (or a byte slice representing it) must have in order to be decoded into a valid ID.
const IDStringLength = 16
// IDLength is the exact length a string (or a byte slice representing it) must have in order to be decoded into a valid ID.
const IDLength = 16
// ErrInvalidID is the error thrown to notify invalid IDs.
var ErrInvalidID = errors.New("invalid ID")
@ -49,11 +49,11 @@ func InvalidID() ID {
// It errors if the input byte slice does not have the correct length
// or if it contains all zeros.
func (i *ID) Decode(b []byte) error {
if len(b) != IDStringLength {
if len(b) != IDLength {
return ErrInvalidIDLength
}
dst := make([]byte, hex.DecodedLen(IDStringLength))
dst := make([]byte, hex.DecodedLen(IDLength))
_, err := hex.Decode(dst, b)
if err != nil {
return err
@ -80,7 +80,7 @@ func (i ID) Encode() ([]byte, error) {
return nil, ErrInvalidID
}
b := make([]byte, hex.DecodedLen(IDStringLength))
b := make([]byte, hex.DecodedLen(IDLength))
binary.BigEndian.PutUint64(b, uint64(i))
dst := make([]byte, hex.EncodedLen(len(b)))

View File

@ -114,7 +114,7 @@ func TestEncode(t *testing.T) {
func TestDecodeFromAllZeros(t *testing.T) {
var id platform.ID
err := id.Decode(make([]byte, platform.IDStringLength))
err := id.Decode(make([]byte, platform.IDLength))
if err == nil {
t.Errorf("expecting all zeros ID to not be a valid ID")
}

View File

@ -6,14 +6,14 @@ import (
"github.com/influxdata/platform"
)
func TestIDStringLength(t *testing.T) {
func TestIDLength(t *testing.T) {
gen := NewIDGenerator()
id := gen.ID()
if !id.Valid() {
t.Fail()
}
enc, _ := id.Encode()
if len(enc) != platform.IDStringLength {
if len(enc) != platform.IDLength {
t.Fail()
}
}