go.mercari.io/datastore@v1.8.2/dsmiddleware/rpcretry/option.go (about)

     1  package rpcretry
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  )
     7  
     8  // WithRetryLimit provides retry limit when RPC failed.
     9  func WithRetryLimit(limit int) RetryOption {
    10  	return &withRetryLimit{limit}
    11  }
    12  
    13  type withRetryLimit struct{ retryLimit int }
    14  
    15  func (w *withRetryLimit) Apply(rh *retryHandler) {
    16  	rh.retryLimit = w.retryLimit
    17  }
    18  
    19  // WithMinBackoffDuration specified minimal duration of retry backoff.
    20  func WithMinBackoffDuration(d time.Duration) RetryOption {
    21  	return &withMinBackoffDuration{d}
    22  }
    23  
    24  type withMinBackoffDuration struct{ d time.Duration }
    25  
    26  func (w *withMinBackoffDuration) Apply(rh *retryHandler) {
    27  	rh.minBackoffDuration = w.d
    28  }
    29  
    30  // WithMaxBackoffDuration specified maximum duratiuon of retry backoff.
    31  func WithMaxBackoffDuration(d time.Duration) RetryOption {
    32  	return &withMaxBackoffDuration{d}
    33  }
    34  
    35  type withMaxBackoffDuration struct{ d time.Duration }
    36  
    37  func (w *withMaxBackoffDuration) Apply(rh *retryHandler) {
    38  	rh.maxBackoffDuration = w.d
    39  }
    40  
    41  // WithMaxDoublings specifies how many times the waiting time should be doubled.
    42  func WithMaxDoublings(maxDoublings int) RetryOption {
    43  	return &withMaxDoublings{maxDoublings}
    44  }
    45  
    46  type withMaxDoublings struct{ maxDoublings int }
    47  
    48  func (w *withMaxDoublings) Apply(rh *retryHandler) {
    49  	rh.maxDoublings = w.maxDoublings
    50  }
    51  
    52  // WithLogger creates a ClientOption that uses the specified logger.
    53  func WithLogger(logf func(ctx context.Context, format string, args ...interface{})) RetryOption {
    54  	return &withLogger{logf}
    55  }
    56  
    57  // WithLogf creates a ClientOption that uses the specified logger.
    58  //
    59  // Deprecated: use WithLogger instead.
    60  func WithLogf(logf func(ctx context.Context, format string, args ...interface{})) RetryOption {
    61  	return WithLogger(logf)
    62  }
    63  
    64  type withLogger struct {
    65  	logf func(ctx context.Context, format string, args ...interface{})
    66  }
    67  
    68  func (w *withLogger) Apply(rh *retryHandler) {
    69  	rh.logf = w.logf
    70  }