-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
44 lines (37 loc) · 949 Bytes
/
option.go
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
package begger
import (
"time"
)
type RetryOptions struct {
// Max number of retry, if the request fails.
MaxAttempt int
/*
Time to wait between two successive requests. For exponential backoff,
it's the wait interval in the first attempt.
*/
WaitInterval *time.Duration
/*
Exponential backoff. This value will be multiplied with the `WaitInterval`
after each retry. And the updated `WaitInterval` will be used in the
next request. Value of `1` indicates simple retry with fixed wait interval.
*/
BackoffRate *float64
}
func (ro *RetryOptions) CleanMaxAttempt() int {
if ro.MaxAttempt < 0 {
return 0
}
return ro.MaxAttempt
}
func (ro *RetryOptions) CleanWaitInterval() time.Duration {
if ro.WaitInterval == nil {
return 0
}
return *ro.WaitInterval
}
func (ro *RetryOptions) CleanBackoffRate() float64 {
if ro.BackoffRate == nil || *ro.BackoffRate <= float64(0) {
return float64(1)
}
return *ro.BackoffRate
}