xnet

package
v0.11.36 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RoundRobinWriter

func RoundRobinWriter(instanceProvider InstanceProvider, sender Sender) io.Writer

RoundRobinWriter returns writer with round robin functionality. Every write could be sent to different backend.

Types

type Address

type Address string

Address of a service in IP:PORT format

type DiscoveryServiceClient

type DiscoveryServiceClient interface {
	// GetAddrsByName returns list of services with given name
	GetAddrsByName(serviceName string) ([]Address, error)
}

DiscoveryServiceClient represents generic discovery service client that can return list of services

func NewConsulDiscoveryServiceClient

func NewConsulDiscoveryServiceClient(client *api.Client) DiscoveryServiceClient

NewConsulDiscoveryServiceClient returns DiscoverServiceClient backed by Consul

type InstanceProvider

type InstanceProvider <-chan []Address

InstanceProvider is the channel where updated list of desired service are published.

func DiscoveryServiceInstanceProvider

func DiscoveryServiceInstanceProvider(serviceName string, interval time.Duration, client DiscoveryServiceClient) InstanceProvider

DiscoveryServiceInstanceProvider returns InstanceProvider that is updated with list of instances in interval

type MultiError

type MultiError []error

MultiError is returned by batch operations when there are errors with particular elements.

func (MultiError) Error

func (m MultiError) Error() string

type Sender

type Sender interface {
	// Send writes given payload to passed address. It returns number of bytes
	// sent and error - if there was any.
	Send(Address, []byte) (int, error)

	// Release frees all system resources allocated by the Sender. It can be
	// called many times - usually when the pool of used addresses changes.
	Release() error
}

Sender is a interface for different sending protocols through the network.

type TCPSender

type TCPSender struct {
	Dialer net.Dialer
	// contains filtered or unexported fields
}

TCPSender is a Sender implementation that can write payload to the network address and reuses TCP connections for the same addresses.

func (*TCPSender) Release

func (s *TCPSender) Release() error

Release frees system sockets used by sender.

func (*TCPSender) Send

func (s *TCPSender) Send(addr Address, payload []byte) (int, error)

Send sends given payload to passed address. Data is sent using pool of TCP connections. It returns number of bytes sent and error - if there was any.

type UDPSender

type UDPSender struct {
	// contains filtered or unexported fields
}

UDPSender is a Sender implementation that can write payload to the network address and reuses single system socket. It uses UDP packets to send data.

func (*UDPSender) Release

func (s *UDPSender) Release() error

Release frees system socket used by sender.

func (*UDPSender) Send

func (s *UDPSender) Send(addr Address, payload []byte) (int, error)

Send sends given payload to passed address. Data is sent using UDP packets. It returns number of bytes sent and error - if there was any.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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