diff --git a/uuid.go b/uuid.go index 7d84b9d..7d656c7 100644 --- a/uuid.go +++ b/uuid.go @@ -79,12 +79,14 @@ func unixTimeFunc() uint64 { return epochStart + uint64(time.Now().UnixNano() / 100) } +// Returns current epoch calculation function. +func GetEpochFunc() (func() uint64) { + return epochFunc +} + // Sets epoch calculation function. -// Returns old function. -func SetEpochFunc(newEpochFunc func() uint64) (func() uint64) { - oldEpochFunc := epochFunc +func SetEpochFunc(newEpochFunc func() uint64) { epochFunc = newEpochFunc - return oldEpochFunc } // UUID representation compliant with specification diff --git a/uuid_test.go b/uuid_test.go index e088c0a..b348155 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -95,13 +95,16 @@ func TestNewV1(t *testing.T) { t.Errorf("UUIDv1 generated two equal UUIDs: %s and %s", u1, u2) } - oldFunc := uuid.SetEpochFunc(func() uint64 { return 0}) + oldFunc := uuid.GetEpochFunc() + + uuid.SetEpochFunc(func() uint64 { return 0}) u3, _ := uuid.NewV1() u4, _ := uuid.NewV1() if uuid.Equal(u3, u4) { t.Errorf("UUIDv1 generated two equal UUIDs: %s and %s", u3, u4) } + uuid.SetEpochFunc(oldFunc) }