...

Package network

import "github.com/gonitro/nitro/app/network"
Overview
Index
Subdirectories

Overview ▾

Package network is an interface for synchronous connection based communication

Variables

var (
    DefaultDialTimeout = time.Second * 5
)

type Client

type Client interface {
    Socket
}

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 {
    // Tells the network this is a streaming connection with
    // multiple calls to send/recv and that send may not even be called
    Stream bool
    // Timeout for dialing
    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 {

    // 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
}

type Option

type Option func(*Options)

func Addrs

func Addrs(addrs ...string) Option

Addrs to use for network

func Codec

func Codec(c codec.Marshaler) Option

Codec sets the codec used for encoding where the network 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 network.

func Timeout

func Timeout(t time.Duration) Option

Timeout sets the timeout for Send/Recv execution

type Options

type Options struct {
    // Addrs is the list of intermediary addresses to connect to
    Addrs []string
    // Codec is the codec interface to use where headers are not supported
    // by the network and the entire payload must be encoded
    Codec codec.Marshaler
    // Secure tells the network to secure the connection.
    // In the case TLSConfig is not specified best effort self-signed
    // certs should be used
    Secure bool
    // TLSConfig to secure the connection. The assumption is that this
    // is mTLS keypair
    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 {
    Recv(*Message) error
    Send(*Message) error
    Close() error
    Local() string
    Remote() string
}

type Transport

Transport is an interface used for communication between services. It uses connection based socket send/recv semantics.

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

Subdirectories

Name Synopsis
..
memory Package memory is an in-memory network
socket Package socket provides a net socket network