transport

package
v0.0.0-...-5dc8409 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDialTimeout = time.Second * 5
)

Functions

func Listen

func Listen(addr string, fn func(string) (net.Listener, error)) (net.Listener, error)

Listen takes addr:portmin-portmax and binds to the first available port Example: Listen("localhost:5000-6000", fn)

Types

type Client

type Client interface {
	Socket
}

Client client interface to implement send, receive, and close methods

type DialOption

type DialOption func(*DialOptions)

func WithStream

func WithStream() DialOption

Indicates whether this is a streaming connection

func WithTimeout

func WithTimeout(d time.Duration) DialOption

Timeout used when dialling the remote side

type DialOptions

type DialOptions struct {
	Stream  bool
	Timeout time.Duration

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

type ListenOption

type ListenOption func(*ListenOptions)

type ListenOptions

type ListenOptions struct {
	// TODO: add tls options when listening
	// Currently set in global options
	// 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
}

Listener interface for to listen the requests and accept the connections

type Option

type Option func(*Options)

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 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 {
	Addrs     []string
	Codec     codec.Codec
	Secure    bool
	TLSConfig *tls.Config
	// Timeout sets the timeout for Send/Recv
	Timeout time.Duration
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Socket

type Socket interface {
	Send(Header []byte, Body []byte, Metadata map[string]string, ID int) error
	Recv() ([]byte, []byte, map[string]string, int, error)
	Close() error
}

Socket wrapp codec and net.conn

type Transport

type Transport interface {
	//return a new client
	Dial(addr string, opts ...DialOption) (Client, error)
	Listen(addr string, opts ...ListenOption) (Listener, error)
	String() string
}

Transport is an interface for communication between services. It uses socket send/recv semantics and could be implemented with various protocol: HTTP, RabbitMQ, NATS, ...

Jump to

Keyboard shortcuts

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