From e9e9b7d99e241d4ddabcac079d92f4656990a06a Mon Sep 17 00:00:00 2001 From: Nebulizer1213 Date: Thu, 21 Jul 2022 04:22:57 -0400 Subject: [PATCH] clean up code --- GinRateLimit.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GinRateLimit.go b/GinRateLimit.go index 0c54bd6..0777d92 100644 --- a/GinRateLimit.go +++ b/GinRateLimit.go @@ -30,12 +30,13 @@ type InMemoryStoreType struct { } func (s *InMemoryStoreType) Limit(key string) (bool, time.Duration) { - _, ok := s.data.Load(key) + var u user + m, ok := s.data.Load(key) if !ok { - s.data.Store(key, user{time.Now().Unix(), s.limit}) + u = user{time.Now().Unix(), s.limit} + } else { + u = m.(user) } - m, _ := s.data.Load(key) - u := m.(user) if u.ts+s.rate <= time.Now().Unix() { u.tokens = s.limit }