distchan: github.com/covrom/distchan Index | Files

package distchan

import "github.com/covrom/distchan"

Index

Package Files

distchan.go

Variables

var (
    ErrorInIsNotChannel  = errors.New("Parameter 'in' is not a channel")
    ErrorOutIsNotChannel = errors.New("Parameter 'out' is not a channel")
    ErrorBadRequest      = errors.New("Bad request format")
)

ErrorInIsNotChannel raises when 'in' is not nil and not a channel ErrorOutIsNotChannel raises when 'out' is not nil and not a channel

type Client Uses

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

Client represents a registration between a network connection and a pair of channels. See the documentation for Server for more details.

func NewClient Uses

func NewClient(conn net.Conn, out, in interface{}) (*Client, error)

func (*Client) AddDecoder Uses

func (c *Client) AddDecoder(f Transformer) *Client

AddDecoder adds a new decoder to the client. Any inbound messages will be passed through all registered decoders before being sent to the channel. See the tests for an example of decoding the data using AES encryption.

func (*Client) AddEncoder Uses

func (c *Client) AddEncoder(f Transformer) *Client

AddEncoder adds a new encoder to the client. Any outbound messages will be passed through all registered encoders before being sent over the wire. See the tests for an example of encoding the data using AES encryption.

func (*Client) Done Uses

func (c *Client) Done() <-chan struct{}

Done returns a channel that will be closed once all in-flight data has been handled.

func (*Client) Logger Uses

func (c *Client) Logger() *log.Logger

Logger exposes the client's internal logger so that it can be configured. For example, if you want the logs to go somewhere besides standard output (the default), you can use c.Logger().SetOutput(...).

func (*Client) Start Uses

func (c *Client) Start() *Client

Start instructs the client to begin serving messages.

type Server Uses

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

Server represents a registration between a network listener and a pair of channels, one for input and one for output.

func NewServer Uses

func NewServer(ln net.Listener, out, in interface{}) (*Server, error)

NewServer registers a pair of channels with an active listener. Gob-encoded messages received on the listener will be passed to in; any values passed to out will be gob-encoded and written to one open connection. The server uses a simple round-robin strategy when deciding which connection to send the message to; no client is favored over any others.

Note that the returned value's Start() method must be called before any messages will be passed. This gives the user an opportunity to register encoders and decoders before any data passes over the network.

func (*Server) AddDecoder Uses

func (s *Server) AddDecoder(f Transformer) *Server

AddDecoder adds a new decoder to the server. Any inbound messages will be passed through all registered decoders before being sent to the channel. See the tests for an example of decoding the data using AES encryption.

func (*Server) AddEncoder Uses

func (s *Server) AddEncoder(f Transformer) *Server

AddEncoder adds a new encoder to the server. Any outbound messages will be passed through all registered encoders before being sent over the wire. See the tests for an example of encoding the data using AES encryption.

func (*Server) Logger Uses

func (s *Server) Logger() *log.Logger

Logger exposes the server's internal logger so that it can be configured. For example, if you want the logs to go somewhere besides standard output (the default), you can use s.Logger().SetOutput(...).

func (*Server) Ready Uses

func (s *Server) Ready() bool

Ready returns true if there are any clients currently connected.

func (*Server) Start Uses

func (s *Server) Start() *Server

Start instructs the server to begin serving messages.

func (*Server) Stop Uses

func (s *Server) Stop()

Stop instructs the server to stop serving messages.

func (*Server) WaitUntilReady Uses

func (s *Server) WaitUntilReady()

WaitUntilReady blocks until the server has at least one client available.

type Transformer Uses

type Transformer func(src io.Reader) io.Reader

Transformer represents a function that does an arbitrary transformation on a piece of data. It's used for defining custom encoders and decoders for modifying how data is sent across the wire.

Package distchan imports 12 packages (graph). Updated 2017-11-22. Refresh now. Tools for package owners.