From 272c8fb2159cd0d0a451433bb1613944508bd679 Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Wed, 10 Apr 2019 01:12:21 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8CLinting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snowflake.go | 12 ++++++------ snowflake_test.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/snowflake.go b/snowflake.go index f112a05..0462cd7 100644 --- a/snowflake.go +++ b/snowflake.go @@ -16,19 +16,19 @@ var ( // You may customize this to set a different epoch for your application. Epoch int64 = 1288834974657 - // Number of bits to use for Node + // NodeBits holds the number of bits to use for Node // Remember, you have a total 22 bits to share between Node/Step NodeBits uint8 = 10 - // Number of bits to use for Step + // StepBits holds the number of bits to use for Step // Remember, you have a total 22 bits to share between Node/Step StepBits uint8 = 12 nodeMax int64 = -1 ^ (-1 << NodeBits) - nodeMask int64 = nodeMax << StepBits + nodeMask = nodeMax << StepBits stepMask int64 = -1 ^ (-1 << StepBits) - timeShift uint8 = NodeBits + StepBits - nodeShift uint8 = StepBits + timeShift = NodeBits + StepBits + nodeShift = StepBits ) const encodeBase32Map = "ybndrfg8ejkmcpqxot1uwisza345h769" @@ -95,7 +95,7 @@ func NewNode(node int64) (*Node, error) { stepMask = -1 ^ (-1 << StepBits) timeShift = NodeBits + StepBits nodeShift = StepBits - + if node < 0 || node > nodeMax { return nil, errors.New("Node number must be between 0 and " + strconv.FormatInt(nodeMax, 10)) } diff --git a/snowflake_test.go b/snowflake_test.go index a454e5a..18f5d9f 100644 --- a/snowflake_test.go +++ b/snowflake_test.go @@ -50,7 +50,7 @@ func TestMarshalsIntBytes(t *testing.T) { func TestUnmarshalJSON(t *testing.T) { tt := []struct { json string - expectedId ID + expectedID ID expectedErr error }{ {`"13587"`, 13587, nil}, @@ -65,8 +65,8 @@ func TestUnmarshalJSON(t *testing.T) { t.Errorf("Expected to get error '%s' decoding JSON, but got '%s'", tc.expectedErr, err) } - if id != tc.expectedId { - t.Errorf("Expected to get ID '%s' decoding JSON, but got '%s'", tc.expectedId, id) + if id != tc.expectedID { + t.Errorf("Expected to get ID '%s' decoding JSON, but got '%s'", tc.expectedID, id) } } }