Documentation ¶
Overview ¶
Package transport is an interface for synchronous connection based communication
Index ¶
- func NewContext(ctx context.Context, c Transport) context.Context
- type Client
- type DialOption
- type DialOptions
- type ListenOption
- type ListenOptions
- type Listener
- type Message
- type Option
- func Addrs(addrs ...string) Option
- func Codec(c codec.Codec) Option
- func Context(ctx context.Context) Option
- func Logger(l logger.Logger) Option
- func Meter(m meter.Meter) Option
- func Name(n string) Option
- func SetOption(k, v interface{}) Option
- func TLSConfig(t *tls.Config) Option
- func Timeout(t time.Duration) Option
- func Tracer(t tracer.Tracer) Option
- type Options
- type Socket
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 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 Option ¶
type Option func(*Options)
Option is the option signature
func Codec ¶
Codec sets the codec used for encoding where the transport does not support message headers
func SetOption ¶
func SetOption(k, v interface{}) Option
SetOption returns a function to setup a context with given value
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
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 ¶
FromContext get transport from context
func NewTransport ¶
NewTransport returns new memory transport with options