From b68a98043de4c76cf539485566ad10ad3c3f91d6 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Wed, 10 Oct 2018 13:57:18 -0500 Subject: [PATCH] refactor(id): update name to IDLength --- bolt/bucket.go | 4 ++-- id.go | 10 +++++----- id_test.go | 2 +- snowflake/id_test.go | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bolt/bucket.go b/bolt/bucket.go index 5556c89c5c..d8ac4c2592 100644 --- a/bolt/bucket.go +++ b/bolt/bucket.go @@ -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 } diff --git a/id.go b/id.go index 44f574c2d2..58a08d61ad 100644 --- a/id.go +++ b/id.go @@ -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))) diff --git a/id_test.go b/id_test.go index 5ce33c7397..29784e1e9b 100644 --- a/id_test.go +++ b/id_test.go @@ -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") } diff --git a/snowflake/id_test.go b/snowflake/id_test.go index d120dc8fca..9c111c0c4d 100644 --- a/snowflake/id_test.go +++ b/snowflake/id_test.go @@ -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() } }