mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
chore: coding style (#3957)
This commit is contained in:
parent
e38036cea2
commit
4e3f1776dc
@ -18,7 +18,7 @@ type (
|
|||||||
times int
|
times int
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
IgnoreErrors []error
|
ignoreErrors []error
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ func retry(ctx context.Context, fn func(errChan chan error, retryCount int), opt
|
|||||||
select {
|
select {
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, ignoreErr := range options.IgnoreErrors {
|
for _, ignoreErr := range options.ignoreErrors {
|
||||||
if errors.Is(err, ignoreErr) {
|
if errors.Is(err, ignoreErr) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -91,29 +91,31 @@ func retry(ctx context.Context, fn func(errChan chan error, retryCount int), opt
|
|||||||
return berr.Err()
|
return berr.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithRetry customize a DoWithRetry call with given retry times.
|
// WithIgnoreErrors Ignore the specified errors
|
||||||
func WithRetry(times int) RetryOption {
|
func WithIgnoreErrors(ignoreErrors []error) RetryOption {
|
||||||
return func(options *retryOptions) {
|
return func(options *retryOptions) {
|
||||||
options.times = times
|
options.ignoreErrors = ignoreErrors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithInterval customizes a DoWithRetry call with given interval.
|
||||||
func WithInterval(interval time.Duration) RetryOption {
|
func WithInterval(interval time.Duration) RetryOption {
|
||||||
return func(options *retryOptions) {
|
return func(options *retryOptions) {
|
||||||
options.interval = interval
|
options.interval = interval
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithTimeout(timeout time.Duration) RetryOption {
|
// WithRetry customizes a DoWithRetry call with given retry times.
|
||||||
|
func WithRetry(times int) RetryOption {
|
||||||
return func(options *retryOptions) {
|
return func(options *retryOptions) {
|
||||||
options.timeout = timeout
|
options.times = times
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithIgnoreErrors Ignore the specified errors
|
// WithTimeout customizes a DoWithRetry call with given timeout.
|
||||||
func WithIgnoreErrors(IgnoreErrors []error) RetryOption {
|
func WithTimeout(timeout time.Duration) RetryOption {
|
||||||
return func(options *retryOptions) {
|
return func(options *retryOptions) {
|
||||||
options.IgnoreErrors = IgnoreErrors
|
options.timeout = timeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user