transport

package
v3.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package transport is an interface for synchronous connection based communication

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext added in v3.1.0

func NewContext(ctx context.Context, c Transport) context.Context

NewContext put transport in context

Types

type Client

type Client interface {
	Socket
}

Client is the socket owner

type DialOption

type DialOption func(*DialOptions)

DialOption is the option signature

func WithStream

func WithStream() DialOption

WithStream indicates whether this is a streaming connection

func WithTimeout

func WithTimeout(d time.Duration) DialOption

WithTimeout used when dialling the remote side

type DialOptions

type DialOptions struct {
	// Context holds the external options
	Context context.Context
	// Timeout holds the timeout
	Timeout time.Duration
	// Stream flag
	Stream bool
}

DialOptions struct

func NewDialOptions

func NewDialOptions(opts ...DialOption) DialOptions

NewDialOptions returns new DialOptions

type ListenOption

type ListenOption func(*ListenOptions)

ListenOption is the option signature

type ListenOptions

type ListenOptions struct {
	// TODO: add tls options when listening
	// Currently set in global options
	// Context holds the external options
	Context context.Context
	// TLSConfig holds the *tls.Config options
	TLSConfig *tls.Config
}

ListenOptions struct

func NewListenOptions

func NewListenOptions(opts ...ListenOption) ListenOptions

NewListenOptions returns new ListenOptions

type Listener

type Listener interface {
	Addr() string
	Close() error
	Accept(func(Socket)) error
}

Listener is the interface for stream oriented messaging

type Message

type Message struct {
	Header metadata.Metadata
	Body   []byte
}

Message is used to transfer data

type Option

type Option func(*Options)

Option is the option signature

func Addrs

func Addrs(addrs ...string) Option

Addrs to use for transport

func Codec

func Codec(c codec.Codec) Option

Codec sets the codec used for encoding where the transport does not support message headers

func Context

func Context(ctx context.Context) Option

Context sets the context

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Meter added in v3.1.6

func Meter(m meter.Meter) Option

Meter sets the meter

func Name added in v3.2.1

func Name(n string) Option

Name sets the name

func SetOption added in v3.1.0

func SetOption(k, v interface{}) Option

SetOption returns a function to setup a context with given value

func TLSConfig

func TLSConfig(t *tls.Config) Option

TLSConfig to be used for the transport.

func Timeout

func Timeout(t time.Duration) Option

Timeout sets the timeout for Send/Recv execution

func Tracer added in v3.1.6

func Tracer(t tracer.Tracer) Option

Tracer to be used for tracing

type Options

type Options struct {
	// Meter used for metrics
	Meter meter.Meter
	// Tracer used for tracing
	Tracer tracer.Tracer
	// Codec used for marshal/unmarshal messages
	Codec codec.Codec
	// Logger used for logging
	Logger logger.Logger
	// Context holds external options
	Context context.Context
	// TLSConfig holds tls.TLSConfig options
	TLSConfig *tls.Config
	// Name holds the transport name
	Name string
	// Addrs holds the transport addrs
	Addrs []string
	// Timeout holds the timeout
	Timeout time.Duration
}

Options struct holds the transport options

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions returns new options

type Socket

type Socket interface {
	Recv(*Message) error
	Send(*Message) error
	Close() error
	Local() string
	Remote() string
}

Socket bastraction interface

type Transport

type Transport interface {
	Init(...Option) error
	Options() Options
	Dial(ctx context.Context, addr string, opts ...DialOption) (Client, error)
	Listen(ctx context.Context, addr string, opts ...ListenOption) (Listener, error)
	String() string
}

Transport is an interface which is used for communication between services. It uses connection based socket send/recv semantics and has various implementations; http, grpc, quic.

var (
	// DefaultTransport is the global default transport
	DefaultTransport Transport = NewTransport()
	// DefaultDialTimeout the default dial timeout
	DefaultDialTimeout = time.Second * 5
)

func FromContext added in v3.1.0

func FromContext(ctx context.Context) (Transport, bool)

FromContext get transport from context

func NewTransport

func NewTransport(opts ...Option) Transport

NewTransport returns new memory transport with options

Jump to

Keyboard shortcuts

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