-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
store: make changes according to the review comments
- Loading branch information
Giedrius Statkevičius
committed
Feb 8, 2019
1 parent
12db24a
commit 9d0b8a7
Showing
4 changed files
with
66 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package store | ||
|
||
import "github.com/pkg/errors" | ||
|
||
// Limiter is a simple mechanism for checking if something has passed a certain threshold. | ||
type Limiter struct { | ||
limit uint64 | ||
} | ||
|
||
// NewLimiter returns a new limiter with a specified limit. 0 disables the limit. | ||
func NewLimiter(limit uint64) *Limiter { | ||
return &Limiter{limit: limit} | ||
} | ||
|
||
// Check checks if the passed number exceeds the limits or not. | ||
func (l *Limiter) Check(num uint64) error { | ||
if l.limit == 0 { | ||
return nil | ||
} | ||
if num > l.limit { | ||
return errors.Errorf("limit %v violated", l.limit) | ||
} | ||
return nil | ||
} |