Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebulizer1213 committed Jul 21, 2022
1 parent f3d5f30 commit e9e9b7d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions GinRateLimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e9e9b7d

Please sign in to comment.