Skip to content

Commit 1f0ea02

Browse files
committed
Tweak comments a bit.
1 parent 51e1998 commit 1f0ea02

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func statusHandler(w http.ResponseWriter, req *http.Request, rateLimiter *rate.L
3939
userID := "user-12345"
4040
limit := int64(5)
4141

42-
//With increment 0, we just retrieve the current limit
42+
// With n=0 we just retrieve the current limit.
4343
rate, reset, allowed := rateLimiter.AllowN(userID, limit, time.Minute, 0)
4444
fmt.Fprintf(w, "Current rate: %d", rate)
4545
fmt.Fprintf(w, "Reset: %d", reset)

rate.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package rate
1+
package rate // import "gopkg.in/go-redis/rate.v4"
22

33
import (
44
"fmt"
@@ -15,15 +15,14 @@ type rediser interface {
1515
Pipelined(func(pipe *redis.Pipeline) error) ([]redis.Cmder, error)
1616
}
1717

18-
//Limiter type
18+
// Limiter controls how frequently events are allowed to happen.
19+
// It uses redis to store data and fallbacks to the fallbackLimiter
20+
// when Redis Server is not available.
1921
type Limiter struct {
2022
fallbackLimiter *timerate.Limiter
2123
redis rediser
2224
}
2325

24-
// NewLimiter creates a limiter that controls how frequently events
25-
// are allowed to happen. It uses redis to store data and fallbacks
26-
// to the fallbackLimiter when Redis Server is not available.
2726
func NewLimiter(redis rediser, fallbackLimiter *timerate.Limiter) *Limiter {
2827
return &Limiter{
2928
fallbackLimiter: fallbackLimiter,
@@ -32,8 +31,8 @@ func NewLimiter(redis rediser, fallbackLimiter *timerate.Limiter) *Limiter {
3231
}
3332

3433
// AllowN reports whether an event with given name may happen at time now.
35-
// It allows up to maxn events within duration dur, with each interaction incrementing
36-
// the limit by n.
34+
// It allows up to maxn events within duration dur, with each interaction
35+
// incrementing the limit by n.
3736
func (l *Limiter) AllowN(name string, maxn int64, dur time.Duration, n int64) (count, reset int64, allow bool) {
3837
udur := int64(dur / time.Second)
3938
slot := time.Now().Unix() / udur
@@ -49,8 +48,7 @@ func (l *Limiter) AllowN(name string, maxn int64, dur time.Duration, n int64) (c
4948
return count, reset, allow
5049
}
5150

52-
// Allow reports whether an event with given name may happen at time now.
53-
// It allows up to maxn events within duration dur.
51+
// Allow is shorthand for AllowN(name, max, dur, 1).
5452
func (l *Limiter) Allow(name string, maxn int64, dur time.Duration) (count, reset int64, allow bool) {
5553
return l.AllowN(name, maxn, dur, 1)
5654
}

0 commit comments

Comments
 (0)