diff --git a/identifier.go b/identifier.go index 763f5bb..b496a86 100644 --- a/identifier.go +++ b/identifier.go @@ -7,7 +7,6 @@ import ( "io" "strings" "sync" - "sync/atomic" ) // Identifier is a unique id. @@ -71,19 +70,6 @@ func cryptoRandIdentifierProvider() (output Identifier) { return } -func counterIdentifierProvider() (output Identifier) { - newCounter := atomic.AddUint64(&identifierCounter, 1) - output[15] = byte(newCounter) - output[14] = byte(newCounter >> 8) - output[13] = byte(newCounter >> 16) - output[12] = byte(newCounter >> 24) - output[11] = byte(newCounter >> 32) - output[10] = byte(newCounter >> 40) - output[9] = byte(newCounter >> 48) - output[8] = byte(newCounter >> 56) - return -} - const randPoolSize = 16 * 16 var ( @@ -92,7 +78,6 @@ var ( identifierRandPoolPos = randPoolSize // protected with poolMu identifierRandPool [randPoolSize]byte // protected with poolMu randomSource = rand.Reader // random function - identifierCounter uint64 ) var zero Identifier diff --git a/identifier_test.go b/identifier_test.go index b787f83..a2a3c27 100644 --- a/identifier_test.go +++ b/identifier_test.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "sync/atomic" "testing" "github.com/wcharczuk/go-incr/testutil" @@ -20,6 +21,21 @@ func Test_Identifier(t *testing.T) { testutil.Equal(t, hex.EncodeToString(id[12:]), id.Short()) } +var identifierCounter uint64 + +func counterIdentifierProvider() (output Identifier) { + newCounter := atomic.AddUint64(&identifierCounter, 1) + output[15] = byte(newCounter) + output[14] = byte(newCounter >> 8) + output[13] = byte(newCounter >> 16) + output[12] = byte(newCounter >> 24) + output[11] = byte(newCounter >> 32) + output[10] = byte(newCounter >> 40) + output[9] = byte(newCounter >> 48) + output[8] = byte(newCounter >> 56) + return +} + func Test_SetIdentifierProvider(t *testing.T) { t.Cleanup(func() { SetIdentifierProvider(cryptoRandIdentifierProvider)