client

package
v0.0.0-...-625ea8d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package client is an interface for an RPC client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallFunc

type CallFunc func(ctx context.Context, node *registry.Node, req Request, opts CallOptions) error

CallFunc represents the individual call func

type CallOption

type CallOption func(*CallOptions)

CallOption used by Call or Stream

func WithCallWrapper

func WithCallWrapper(cw ...CallWrapper) CallOption

WithCallWrapper is a CallOption which adds to the existing CallFunc wrappers

func WithSelectOption

func WithSelectOption(so ...selector.SelectOption) CallOption

WithSelectOption select option

type CallOptions

type CallOptions struct {
	SelectOptions []selector.SelectOption

	// Middleware for low level call func
	CallWrappers []CallWrapper

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

CallOptions call options

type CallWrapper

type CallWrapper func(CallFunc) CallFunc

CallWrapper is a low level wrapper for the CallFunc

type Client

type Client interface {
	Init(...Option) error
	Options() Options
	Handle(interface{}) error
	NewRequest(service, method string, req interface{}) Request
	Call(ctx context.Context, req Request, opts ...CallOption) error
	Broadcast(ctx context.Context, req Request, opts ...CallOption)
	String() string
}

Client is the interface used to make requests to services. It supports Request/Response via Transport and Publishing via the Broker. It also supports bidirectional streaming of requests.

type Option

type Option func(*Options)

Option used by the Client

func Codec

func Codec(contentType string, c codec.NewCodec) Option

Codec to be used to encode/decode requests for a given content type

func Connector

func Connector(ct connector.Connector) Option

Connector connector

func ContentType

func ContentType(ct string) Option

ContentType Default content type of the client

func Registry

func Registry(r registry.Registry) Option

Registry to find nodes for a given service

func Selector

func Selector(s selector.Selector) Option

Selector Select is used to select a node to route a request to

func Transport

func Transport(t transport.Transport) Option

Transport to use for communication e.g http, rabbitmq, etc

func Wrap

func Wrap(w Wrapper) Option

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

func WrapCall

func WrapCall(cw ...CallWrapper) Option

WrapCall Adds a Wrapper to the list of CallFunc wrappers

type Options

type Options struct {
	// Used to select codec
	ContentType string

	// Plugged interfaces
	Codecs    map[string]codec.NewCodec
	Registry  registry.Registry
	Selector  selector.Selector
	Connector connector.Connector
	Transport transport.Transport

	// 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
}

Options options

type Request

type Request interface {
	// The request id
	ID() string
	// The service to call
	Service() string
	// The action to take
	Method() string
	// The content type
	ContentType() string
	// The unencoded request body
	Body() interface{}
}

Request is the interface for a synchronous request used by Call or 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