-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
64 lines (53 loc) · 1.7 KB
/
debug.go
File metadata and controls
64 lines (53 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package rate
import (
"time"
)
// Debug is a struct that contains the details of a rate limit check for a single bucket.
// Used by debug APIs that return per-bucket information.
type Debug[TInput any, TKey comparable] struct {
allowed bool
executionTime time.Time
input TInput
key TKey
limit Limit
tokensRequested int64
tokensConsumed int64
tokensRemaining int64
retryAfter time.Duration
}
// Allowed returns true if the request was allowed.
func (d Debug[TInput, TKey]) Allowed() bool {
return d.allowed
}
// Limit returns the limit that was used for the request.
func (d Debug[TInput, TKey]) Limit() Limit {
return d.limit
}
// ExecutionTime returns the time the request was executed.
func (d Debug[TInput, TKey]) ExecutionTime() time.Time {
return d.executionTime
}
// Input returns the input that was used to create the bucket.
func (d Debug[TInput, TKey]) Input() TInput {
return d.input
}
// Key returns the key of the bucket that was used for the request.
func (d Debug[TInput, TKey]) Key() TKey {
return d.key
}
// TokensRequested returns the number of tokens that were requested for the request.
func (d Debug[TInput, TKey]) TokensRequested() int64 {
return d.tokensRequested
}
// TokensConsumed returns the number of tokens that were consumed for the request.
func (d Debug[TInput, TKey]) TokensConsumed() int64 {
return d.tokensConsumed
}
// TokensRemaining returns the number of remaining tokens in the bucket
func (d Debug[TInput, TKey]) TokensRemaining() int64 {
return d.tokensRemaining
}
// RetryAfter returns the duration after which the bucket may have refilled.
func (d Debug[TInput, TKey]) RetryAfter() time.Duration {
return d.retryAfter
}