Skip to content

Commit 472e2d0

Browse files
committed
refactor: make Retry middleware variadic to make options passing optional
1 parent 000c5f1 commit 472e2d0

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

pkg/builtin/middlewares/retry.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,27 @@ func defaultOpts() *RetryOpts {
7171
return opts
7272
}
7373

74-
func Retry(opts RetryOpts) func(http.RoundTripper) http.RoundTripper {
74+
func Retry(opts ...RetryOpts) func(http.RoundTripper) http.RoundTripper {
7575

7676
retryOpts := defaultOpts()
7777

78-
if opts.MaxRetries > 0 {
79-
retryOpts.MaxRetries = opts.MaxRetries
80-
}
78+
// overwrite defaults
79+
if len(opts) > 0 {
80+
if opts[0].MaxRetries > 0 {
81+
retryOpts.MaxRetries = opts[0].MaxRetries
82+
}
8183

82-
if opts.Codes != nil {
83-
retryOpts.Codes = opts.Codes[:]
84-
}
84+
if opts[0].Codes != nil {
85+
retryOpts.Codes = opts[0].Codes[:]
86+
}
8587

86-
if opts.BaseDelay > 0 {
87-
retryOpts.BaseDelay = opts.BaseDelay
88-
}
88+
if opts[0].BaseDelay > 0 {
89+
retryOpts.BaseDelay = opts[0].BaseDelay
90+
}
8991

90-
if opts.Cb != nil {
91-
retryOpts.Cb = opts.Cb
92+
if opts[0].Cb != nil {
93+
retryOpts.Cb = opts[0].Cb
94+
}
9295
}
9396

9497
return func(next http.RoundTripper) http.RoundTripper {

0 commit comments

Comments
 (0)