Add call func wrapper

This commit is contained in:
Asim
2016-11-07 17:49:35 +00:00
parent d1d41b5a67
commit c6b5237cce
3 changed files with 40 additions and 1 deletions

View File

@@ -52,6 +52,9 @@ type CallOptions struct {
// Request/Response timeout
RequestTimeout time.Duration
// Middleware for low level call func
CallWrappers []CallFuncWrapper
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
@@ -177,6 +180,13 @@ func Wrap(w Wrapper) Option {
}
}
// Adds a Wrapper to the list of CallFunc wrappers
func WrapCallFunc(cw ...CallFuncWrapper) Option {
return func(o *Options) {
o.CallOptions.CallWrappers = append(o.CallOptions.CallWrappers, cw...)
}
}
// Backoff is used to set the backoff function used
// when retrying Calls
func Backoff(fn BackoffFunc) Option {
@@ -216,6 +226,13 @@ func WithSelectOption(so ...selector.SelectOption) CallOption {
}
}
// WithCallFuncWrapper is a CallOption which adds to the existing CallFunc wrappers
func WithCallFuncWrapper(cw ...CallFuncWrapper) CallOption {
return func(o *CallOptions) {
o.CallWrappers = append(o.CallWrappers, cw...)
}
}
// WithBackoff is a CallOption which overrides that which
// set in Options.CallOptions
func WithBackoff(fn BackoffFunc) CallOption {