client

package
v0.0.0-...-b02c517 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Backoff:  nil,
	Breaker:  nil,
	Selector: nil,
}
View Source
var ErrBreakerOpen = errors.New("circuit breaker is open")

Functions

This section is empty.

Types

type CallOption

type CallOption func(*CallOptions)

func Codec

func Codec(b codec.Builder) CallOption

func Retries

func Retries(n int) CallOption

type CallOptions

type CallOptions struct {
	// Retries specifies a retry limit before a call actually fails.
	Retries int
	// CodecBuilder specifies a function to create a codec.
	CodecBuilder codec.Builder
}

type Client

type Client interface {
	// Init initializes the client using the given optional functions.
	// By default, the DefaultOptions will be used to create the client.
	Init(...Option)
	// Connect creates a virtual connection to a service. Note that only
	// the first call will open a new connection before which is closed.
	Connect(string) (Conn, error)
	// Stream returns a stream to a service endpoint. This method calls
	// Open to get a virtual connection in which the stream works.
	Stream(*Request, ...CallOption) (stream.Stream, error)
	// Invoke simply wraps Stream to make an unary call to the service.
	// TODO: Does it take too much to make such unary call by that??
	Invoke(*Request, any, any, ...CallOption) error
}

Client is a dynamic client that makes RPC calls to any service.

var Default Client

func New

func New(opts ...Option) Client

type Conn

type Conn interface {
	// Open opens a stream to a specific service endpoint.
	Open(*http.Request, codec.Builder) (stream.Stream, error)
	// Close closes the virtual connection itself.
	Close() error
}

Conn abstracts the virtual connection to a service.

type Option

type Option func(*Options)

func Backoff

func Backoff(b backoff.Backoff) Option

func Breaker

func Breaker(b breaker.Builder) Option

func Network

func Network(name string) Option

func Registry

func Registry(r registry.Registry) Option

func Selector

func Selector(b selector.Builder) Option

func TLSConfig

func TLSConfig(c *tls.Config) Option

func Timeout

func Timeout(d time.Duration) Option

func Transport

func Transport(t transport.Transport) Option

type Options

type Options struct {
	// Network specifies the network of the client itself.
	Network string
	// TLSConfig specifies the TLS configuration for dialer.
	TLSConfig *tls.Config
	// Timeout specifies a time limit for streams made by the client.
	Timeout time.Duration
	// Transport specifies a transport provider for communication.
	Transport transport.Transport
	// Registry specifies registry for service discovery.
	Registry registry.Registry
	// Backoff specifies a backoff implementation for retries.
	Backoff backoff.Backoff
	// Breaker specifies a circuit breaker builder.
	Breaker breaker.Builder
	// Selector specifies node selector builder.
	Selector selector.Builder
}

type Request

type Request struct {
	// Service specifies which service to connect to.
	Service string
	// Endpoint specifies which endpoint of the service to call.
	Endpoint string
	// Context is used for timing out the call. If nil, a todo context will be used.
	Context context.Context
}

Jump to

Keyboard shortcuts

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