@@ -15,8 +15,8 @@ type LimitCounter interface {
15
15
Get (key string , currentWindow , previousWindow time.Time ) (int , int , error )
16
16
}
17
17
18
- func NewRateLimiter (requestLimit int , windowLength time.Duration , options ... Option ) * rateLimiter {
19
- rl := & rateLimiter {
18
+ func NewRateLimiter (requestLimit int , windowLength time.Duration , options ... Option ) * RateLimiter {
19
+ rl := & RateLimiter {
20
20
requestLimit : requestLimit ,
21
21
windowLength : windowLength ,
22
22
headers : ResponseHeaders {
@@ -55,7 +55,7 @@ func NewRateLimiter(requestLimit int, windowLength time.Duration, options ...Opt
55
55
return rl
56
56
}
57
57
58
- type rateLimiter struct {
58
+ type RateLimiter struct {
59
59
requestLimit int
60
60
windowLength time.Duration
61
61
keyFn KeyFunc
@@ -70,7 +70,7 @@ type rateLimiter struct {
70
70
// and automatically sends HTTP response. The caller should halt further request processing.
71
71
// If the limit is not reached, it increments the request count and returns false, allowing
72
72
// the request to proceed.
73
- func (l * rateLimiter ) OnLimit (w http.ResponseWriter , r * http.Request , key string ) bool {
73
+ func (l * RateLimiter ) OnLimit (w http.ResponseWriter , r * http.Request , key string ) bool {
74
74
currentWindow := time .Now ().UTC ().Truncate (l .windowLength )
75
75
ctx := r .Context ()
76
76
@@ -116,15 +116,15 @@ func (l *rateLimiter) OnLimit(w http.ResponseWriter, r *http.Request, key string
116
116
return false
117
117
}
118
118
119
- func (l * rateLimiter ) Counter () LimitCounter {
119
+ func (l * RateLimiter ) Counter () LimitCounter {
120
120
return l .limitCounter
121
121
}
122
122
123
- func (l * rateLimiter ) Status (key string ) (bool , float64 , error ) {
123
+ func (l * RateLimiter ) Status (key string ) (bool , float64 , error ) {
124
124
return l .calculateRate (key , l .requestLimit )
125
125
}
126
126
127
- func (l * rateLimiter ) Handler (next http.Handler ) http.Handler {
127
+ func (l * RateLimiter ) Handler (next http.Handler ) http.Handler {
128
128
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
129
129
key , err := l .keyFn (r )
130
130
if err != nil {
@@ -140,7 +140,7 @@ func (l *rateLimiter) Handler(next http.Handler) http.Handler {
140
140
})
141
141
}
142
142
143
- func (l * rateLimiter ) calculateRate (key string , requestLimit int ) (bool , float64 , error ) {
143
+ func (l * RateLimiter ) calculateRate (key string , requestLimit int ) (bool , float64 , error ) {
144
144
now := time .Now ().UTC ()
145
145
currentWindow := now .Truncate (l .windowLength )
146
146
previousWindow := currentWindow .Add (- l .windowLength )
0 commit comments