@@ -11,8 +11,21 @@ import (
|
||||
|
||||
var (
|
||||
// DefaultClient is the global default client
|
||||
DefaultClient Client = NewClient()
|
||||
DefaultContentType = "application/json"
|
||||
DefaultClient Client = NewClient()
|
||||
// DefaultContentType is the default content-type if not specified
|
||||
DefaultContentType = "application/json"
|
||||
// DefaultBackoff is the default backoff function for retries
|
||||
DefaultBackoff = exponentialBackoff
|
||||
// DefaultRetry is the default check-for-retry function for retries
|
||||
DefaultRetry = RetryNever
|
||||
// DefaultRetries is the default number of times a request is tried
|
||||
DefaultRetries = 0
|
||||
// DefaultRequestTimeout is the default request timeout
|
||||
DefaultRequestTimeout = time.Second * 5
|
||||
// DefaultPoolSize sets the connection pool size
|
||||
DefaultPoolSize = 100
|
||||
// DefaultPoolTTL sets the connection pool ttl
|
||||
DefaultPoolTTL = time.Minute
|
||||
)
|
||||
|
||||
// Client is the interface used to make requests to services.
|
||||
@@ -20,10 +33,10 @@ var (
|
||||
// It also supports bidirectional streaming of requests.
|
||||
type Client interface {
|
||||
Name() string
|
||||
Init(...Option) error
|
||||
Init(opts ...Option) error
|
||||
Options() Options
|
||||
NewMessage(topic string, msg interface{}, opts ...MessageOption) Message
|
||||
NewRequest(service, endpoint string, req interface{}, reqOpts ...RequestOption) Request
|
||||
NewRequest(service string, endpoint string, req interface{}, opts ...RequestOption) Request
|
||||
Call(ctx context.Context, req Request, rsp interface{}, opts ...CallOption) error
|
||||
Stream(ctx context.Context, req Request, opts ...CallOption) (Stream, error)
|
||||
Publish(ctx context.Context, msg Message, opts ...PublishOption) error
|
||||
@@ -74,9 +87,9 @@ type Stream interface {
|
||||
// The response read
|
||||
Response() Response
|
||||
// Send will encode and send a request
|
||||
Send(interface{}) error
|
||||
Send(msg interface{}) error
|
||||
// Recv will decode and read a response
|
||||
Recv(interface{}) error
|
||||
Recv(msg interface{}) error
|
||||
// Error returns the stream error
|
||||
Error() error
|
||||
// Close closes the stream
|
||||
@@ -97,18 +110,3 @@ type MessageOption func(*MessageOptions)
|
||||
|
||||
// RequestOption used by NewRequest
|
||||
type RequestOption func(*RequestOptions)
|
||||
|
||||
var (
|
||||
// DefaultBackoff is the default backoff function for retries
|
||||
DefaultBackoff = exponentialBackoff
|
||||
// DefaultRetry is the default check-for-retry function for retries
|
||||
DefaultRetry = RetryNever
|
||||
// DefaultRetries is the default number of times a request is tried
|
||||
DefaultRetries = 0
|
||||
// DefaultRequestTimeout is the default request timeout
|
||||
DefaultRequestTimeout = time.Second * 5
|
||||
// DefaultPoolSize sets the connection pool size
|
||||
DefaultPoolSize = 100
|
||||
// DefaultPoolTTL sets the connection pool ttl
|
||||
DefaultPoolTTL = time.Minute
|
||||
)
|
||||
|
||||
@@ -64,13 +64,13 @@ type CallOptions struct {
|
||||
Address []string
|
||||
// Backoff func
|
||||
Backoff BackoffFunc
|
||||
// Transport Dial Timeout
|
||||
// DialTimeout is the transport Dial Timeout
|
||||
DialTimeout time.Duration
|
||||
// Number of Call attempts
|
||||
// Retries is the number of Call attempts
|
||||
Retries int
|
||||
// Check if retriable func
|
||||
// Retry func to be used for retries
|
||||
Retry RetryFunc
|
||||
// Request/Response timeout
|
||||
// RequestTimeout specifies request timeout
|
||||
RequestTimeout time.Duration
|
||||
// Router to use for this call
|
||||
Router router.Router
|
||||
@@ -78,15 +78,15 @@ type CallOptions struct {
|
||||
Selector selector.Selector
|
||||
// SelectOptions to use when selecting a route
|
||||
SelectOptions []selector.SelectOption
|
||||
// Stream timeout for the stream
|
||||
// StreamTimeout timeout for the stream
|
||||
StreamTimeout time.Duration
|
||||
// Use the auth token as the authorization header
|
||||
// AuthToken specifies the auth token as the authorization header
|
||||
AuthToken bool
|
||||
// Network to lookup the route within
|
||||
Network string
|
||||
// Middleware for low level call func
|
||||
// CallWrappers is for low level call func
|
||||
CallWrappers []CallWrapper
|
||||
// Context is uded for non default options
|
||||
// Context is used for non default options
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
@@ -110,8 +110,7 @@ func NewPublishOptions(opts ...PublishOption) PublishOptions {
|
||||
type PublishOptions struct {
|
||||
// Exchange is the routing exchange for the message
|
||||
Exchange string
|
||||
// Other options for implementations of the interface
|
||||
// can be stored in a context
|
||||
// Context holds additional options
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
@@ -140,10 +139,11 @@ func NewRequestOptions(opts ...RequestOption) RequestOptions {
|
||||
|
||||
// RequestOptions holds client request options
|
||||
type RequestOptions struct {
|
||||
// ContentType specify content-type of request
|
||||
ContentType string
|
||||
Stream bool
|
||||
// Other options for implementations of the interface
|
||||
// can be stored in a context
|
||||
// Stream says that request is the streaming
|
||||
Stream bool
|
||||
// Context can hold other options
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ func Codec(contentType string, c codec.Codec) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Default content type of the client
|
||||
// ContentType used by default if not specified
|
||||
func ContentType(ct string) Option {
|
||||
return func(o *Options) {
|
||||
o.ContentType = ct
|
||||
@@ -270,22 +270,21 @@ func Selector(s selector.Selector) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a Wrapper to a list of options passed into the client
|
||||
// Wrap adds a wrapper to the list of options passed into the client
|
||||
func Wrap(w Wrapper) Option {
|
||||
return func(o *Options) {
|
||||
o.Wrappers = append(o.Wrappers, w)
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a Wrapper to the list of CallFunc wrappers
|
||||
// WrapCall adds a wrapper to the list of CallFunc wrappers
|
||||
func WrapCall(cw ...CallWrapper) 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
|
||||
// Backoff is used to set the backoff function used when retrying Calls
|
||||
func Backoff(fn BackoffFunc) Option {
|
||||
return func(o *Options) {
|
||||
o.CallOptions.Backoff = fn
|
||||
@@ -307,7 +306,6 @@ func Lookup(l LookupFunc) Option {
|
||||
}
|
||||
|
||||
// Retries sets the retry count when making the request.
|
||||
// Should this be a Call Option?
|
||||
func Retries(i int) Option {
|
||||
return func(o *Options) {
|
||||
o.CallOptions.Retries = i
|
||||
@@ -322,7 +320,6 @@ func Retry(fn RetryFunc) Option {
|
||||
}
|
||||
|
||||
// RequestTimeout is the request timeout.
|
||||
// Should this be a Call Option?
|
||||
func RequestTimeout(d time.Duration) Option {
|
||||
return func(o *Options) {
|
||||
o.CallOptions.RequestTimeout = d
|
||||
@@ -463,8 +460,6 @@ func WithMessageContentType(ct string) MessageOption {
|
||||
}
|
||||
}
|
||||
|
||||
// Request Options
|
||||
|
||||
// WithContentType specifies request content type
|
||||
func WithContentType(ct string) RequestOption {
|
||||
return func(o *RequestOptions) {
|
||||
|
||||
Reference in New Issue
Block a user