client

package
v0.0.0-...-1506a89 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackoffFunc

type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error)

type CallFunc

type CallFunc func(ctx context.Context, node *node.Node, req Request, rsp interface{}, opts CallOptions) error

CallFunc represents the individual call func

type CallOption

type CallOption func(*CallOptions)

CallOption used by Call or Stream

type CallOptions

type CallOptions struct {

	// Router to use for this call
	Caller message.Caller
}

type CallWrapper

type CallWrapper func(CallFunc) CallFunc

CallWrapper is a low level wrapper for the CallFunc

type Client

type Client interface {
	NewMessage(msg interface{}, opts ...MessageOption) Message
	NewRequest(service *service.Service, endpoint string, req interface{}, reqOpts ...RequestOption) Request

	Call(ctx context.Context, req Request, rsp interface{}, opts ...CallOption) error

	Publish(ctx context.Context, msg Message, opts ...PublishOption) error
	Stream(ctx context.Context, req Request, opts ...CallOption) (Stream, error)

	String() string
}

Client client

var DefaultClient Client

DefaultClient implementation

type Message

type Message interface {
	Topic() string
	Payload() interface{}
	ContentType() string
}

Message is the interface for publishing asynchronously

type MessageOption

type MessageOption func(*MessageOptions)

MessageOption used by NewMessage

type MessageOptions

type MessageOptions struct {
	ContentType string
}

type Option

type Option func(*Options)

Option used by the Client

func ContentType

func ContentType(ct string) Option

ContentType Default content type of the client

func PoolSize

func PoolSize(d int) Option

PoolSize sets the connection pool size

func PoolTTL

func PoolTTL(d time.Duration) Option

PoolTTL sets the connection pool ttl

func Proxy

func Proxy(addr string) Option

Proxy sets the proxy address

func Wrap

func Wrap(w Wrapper) Option

Wrap Adds a Wrapper to a list of options passed into the client

type Options

type Options struct {
	// Used to select codec
	ContentType string
	// Proxy address to send requests via
	Proxy string

	// Connection Pool
	PoolSize int
	PoolTTL  time.Duration

	// Middleware for client
	Wrappers []Wrapper

	// Default Call Options
	CallOptions CallOptions

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

func NewOptions

func NewOptions(options ...Option) Options

type PublishOption

type PublishOption func(*PublishOptions)

PublishOption used by Publish

type 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 context.Context
}

type Request

type Request interface {
	// Service The service to call
	Service() *service.Service
	// Method The action to take
	Method() string
	// Endpoint The endpoint to invoke
	Endpoint() string
	// ContentType The content type
	ContentType() string
	// Body The unencoded request body
	Body() interface{}
	// Codec Write to the encoded request writer. This is nil before a call is made
	Codec() codec.Codec
	// Stream indicates whether the request will be a streaming one rather than unary
	Stream() bool
}

Request is the interface for a synchronous request used by Call or Stream

type RequestOption

type RequestOption func(*RequestOptions)

RequestOption used by NewRequest

type RequestOptions

type RequestOptions struct {
	ContentType string
	Stream      bool

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Response

type Response interface {
	// Codec Reader the response
	Codec() codec.Codec
	// Header read the header
	Header() map[string]string
	// Read the undecoded response
	Read() ([]byte, error)
}

Response is the response received from a service

type RetryFunc

type RetryFunc func(ctx context.Context, req Request, retryCount int, err error) (bool, error)

RetryFunc note that returning either false or a non-nil error will result in the call not being retried

type Stream

type Stream interface {
	// Context for the stream
	Context() context.Context
	// Request The request made
	Request() Request
	// Response The response read
	Response() Response
	// Send will encode and send a request
	Send(interface{}) error
	// Recv will decode and read a response
	Recv(interface{}) error
	// Error returns the stream error
	Error() error
	// Close closes the stream
	Close() error
}

Stream is the interface for a bidirectional synchronous stream

type Wrapper

type Wrapper func(Client) Client

Wrapper wraps a client and returns a client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL