From 775347374d164acac1382c57b88977348a7cd4a1 Mon Sep 17 00:00:00 2001 From: ikouchiha47 Date: Tue, 5 Mar 2024 01:53:51 +0530 Subject: [PATCH] feat: adds an interface to the struct --- generator.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/generator.go b/generator.go index bee3127..d84429b 100644 --- a/generator.go +++ b/generator.go @@ -26,6 +26,10 @@ const ( customEpoch = 1420070400000 ) +type SnowflakeGenerator interface { + NextID() int64 +} + type SequenceGenerator struct { mu sync.Mutex lastTimeStamp int64 @@ -57,7 +61,7 @@ func (s *SequenceGenerator) NextID() int64 { s.mu.Lock() defer s.mu.Unlock() - var currentTimestamp = timestamp() + currentTimestamp := timestamp() if currentTimestamp < s.lastTimeStamp { panic("system clock is destroyed")