transport

package
v4.11.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 25 Imported by: 60

Documentation

Overview

Package transport is an interface for synchronous connection based communication

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBufSizeH2 = 4 * 1024 * 1024
)

Functions

func NewHTTPTransport

func NewHTTPTransport(opts ...Option) *httpTransport

Types

type Client

type Client interface {
	Socket
}

type DialOption

type DialOption func(*DialOptions)

func WithConnClose added in v4.10.0

func WithConnClose() DialOption

WithConnClose sets the Connection header to close.

func WithInsecureSkipVerify added in v4.10.0

func WithInsecureSkipVerify(b bool) DialOption

func WithStream

func WithStream() DialOption

Indicates whether this is a streaming connection.

func WithTimeout

func WithTimeout(d time.Duration) DialOption

type DialOptions

type DialOptions struct {

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
	// Timeout for dialing
	Timeout time.Duration
	// Tells the transport this is a streaming connection with
	// multiple calls to send/recv and that send may not even be called
	Stream bool
	// ConnClose sets the Connection header to close
	ConnClose bool
	// InsecureSkipVerify skip TLS verification.
	InsecureSkipVerify bool
}

type ListenOption

type ListenOption func(*ListenOptions)

func NetListener added in v4.8.1

func NetListener(customListener net.Listener) ListenOption

InsecureSkipVerify sets the TLS options to skip verification. NetListener Set net.Listener for httpTransport.

type ListenOptions

type ListenOptions struct {

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

type Listener

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

type Message

type Message struct {
	Header map[string]string
	Body   []byte
}

Message is a broker message.

type Option

type Option func(*Options)

func Addrs

func Addrs(addrs ...string) Option

Addrs to use for transport.

func BuffSizeH2 added in v4.10.0

func BuffSizeH2(size int) Option

BuffSizeH2 sets the HTTP2 buffer size. Default is 4 * 1024 * 1024.

func Codec

func Codec(c codec.Marshaler) Option

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

func Logger added in v4.10.0

func Logger(l logger.Logger) Option

Logger sets the underline logger.

func Secure

func Secure(b bool) Option

Use secure communication. If TLSConfig is not specified we use InsecureSkipVerify and generate a self signed cert.

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.

type Options

type Options struct {
	// Codec is the codec interface to use where headers are not supported
	// by the transport and the entire payload must be encoded
	Codec codec.Marshaler
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
	// Logger is the underline logger
	Logger logger.Logger
	// TLSConfig to secure the connection. The assumption is that this
	// is mTLS keypair
	TLSConfig *tls.Config
	// Addrs is the list of intermediary addresses to connect to
	Addrs []string
	// Timeout sets the timeout for Send/Recv
	Timeout time.Duration
	// BuffSizeH2 is the HTTP2 buffer size
	BuffSizeH2 int
	// Secure tells the transport to secure the connection.
	// In the case TLSConfig is not specified best effort self-signed
	// certs should be used
	Secure bool
}

type Socket

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

type Transport

type Transport interface {
	Init(...Option) error
	Options() Options
	Dial(addr string, opts ...DialOption) (Client, error)
	Listen(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 Transport = NewHTTPTransport()

	DefaultDialTimeout = time.Second * 5
)

func NewMemoryTransport

func NewMemoryTransport(opts ...Option) Transport

Directories

Path Synopsis
broker
memory module
cmd module
server/rpc module
codec module
client module
client/mock module
client/rpc module
server/debug module
etcd module
grpc module
proto module
transport module
headers is a package for internal micro global constants
headers is a package for internal micro global constants
codec/json module
http module
broker module
broker/http module
broker/memory module
client/mock module
client/rpc module
cmd module
codec module
codec/bytes module
codec/grpc module
codec/json module
codec/jsonrpc module
codec/proto module
errors module
metadata module
registry module
registry/mdns module
selector module
selector/dns module
server module
server/debug module
server/mock module
server/rpc module
transport module
memory module
message module
transport module
mqtt module
selector/dns module
nats module
noop module
quic module
registry module
registry/mdns module
tcp module

Jump to

Keyboard shortcuts

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