Documentation ¶
Overview ¶
Package pakt provides access to exported methods across a network or other I/O connections similar to RPC. It handles any I/O connection which implements the golang net.Conn interface.
Index ¶
- Constants
- Variables
- type CallHook
- type ClosedChan
- type Context
- type ErrorHook
- type Func
- type Funcs
- type OnCloseFunc
- type Server
- func (s *Server) Close()
- func (s *Server) ClosedChan() ClosedChan
- func (s *Server) GetSocket(id string) (so *Socket)
- func (s *Server) IsClosed() bool
- func (s *Server) Listen()
- func (s *Server) NewSocketChan() <-chan *Socket
- func (s *Server) OnClose(f func())
- func (s *Server) OnNewSocket(f func(*Socket))
- func (s *Server) Sockets() []*Socket
- type Socket
- func (s *Socket) Call(id string, args ...interface{}) (*Context, error)
- func (s *Socket) Close() error
- func (s *Socket) ClosedChan() ClosedChan
- func (s *Socket) ID() string
- func (s *Socket) IsClosed() bool
- func (s *Socket) LocalAddr() net.Addr
- func (s *Socket) OnClose(f OnCloseFunc)
- func (s *Socket) Ready()
- func (s *Socket) RegisterFunc(id string, f Func)
- func (s *Socket) RegisterFuncs(funcs Funcs)
- func (s *Socket) RemoteAddr() net.Addr
- func (s *Socket) SetCallHook(h CallHook)
- func (s *Socket) SetCallTimeout(t time.Duration)
- func (s *Socket) SetErrorHook(h ErrorHook)
- func (s *Socket) SetMaxMessageSize(size int)
Constants ¶
const ( // ProtocolVersion defines the protocol version defined in the specifications. ProtocolVersion byte = 0 // DefaultMaxMessageSize specifies the default maximum message payload size in KiloBytes. DefaultMaxMessageSize = 100 * 1024 // DefaultCallTimeout specifies the default timeout for a call request. DefaultCallTimeout = 30 * time.Second )
Variables ¶
var ( // ErrClosed defines the error if the socket connection is closed. ErrClosed = errors.New("socket closed") // ErrTimeout defines the error if the call timeout is reached. ErrTimeout = errors.New("timeout") // ErrMaxMsgSizeExceeded if the maximum message size is exceeded for a call request. ErrMaxMsgSizeExceeded = errors.New("maximum message size exceeded") )
var ( // ErrNoContextData defines the error if no context data is available. ErrNoContextData = errors.New("no context data available to decode") )
var ( // Log is the public logrus value used internally. Log *logrus.Logger )
Functions ¶
This section is empty.
Types ¶
type ClosedChan ¶
type ClosedChan <-chan struct{}
ClosedChan defines a channel which is closed as soon as the socket is closed.
type Context ¶
type Context struct { // Data is the raw byte representation of the encoded context data. Data []byte // contains filtered or unexported fields }
A Context defines a function context.
type OnCloseFunc ¶
type OnCloseFunc func(s *Socket)
OnCloseFunc defines the callback function which is triggered as soon as the socket closes.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server defines the PAKT server implementation.
func (*Server) Close ¶
func (s *Server) Close()
Close the server and disconnect all connected sockets.
func (*Server) ClosedChan ¶
func (s *Server) ClosedChan() ClosedChan
ClosedChan returns a channel which is closed as soon as the network listener is closed.
func (*Server) Listen ¶
func (s *Server) Listen()
Listen for new socket connections. This method is blocking.
func (*Server) NewSocketChan ¶
NewSocketChan returns the channel for new incoming sockets. Either use NewSocketChan or OnNewSocket.
func (*Server) OnClose ¶
func (s *Server) OnClose(f func())
OnClose triggers the function as soon as the network listener closes. This method can be called multiple times to bind multiple functions.
func (*Server) OnNewSocket ¶
OnNewSocket sets the function which is triggered if a new socket connection was made. Only set this during initialization and only set this once! The callback function is called in a new goroutine. Either use NewSocketChan or OnNewSocket.
type Socket ¶
type Socket struct { // Value is a custom value which can be set. Value interface{} // Codec holds the encoding and decoding interface. Codec codec.Codec // contains filtered or unexported fields }
Socket defines the PAKT socket implementation.
func NewSocket ¶
NewSocket creates a new PAKT socket using the passed connection. One variadic argument specifies the socket ID. Ready() must be called to start the socket read routine.
func (*Socket) Call ¶
Call a remote function and wait for its result. This method blocks until the remote socket function returns. The first variadic argument specifies an optional data value [interface{}]. The second variadic argument specifies an optional call timeout time.Duration. Returns ErrTimeout on a timeout. Returns ErrClosed if the connection is closed. This method is thread-safe.
func (*Socket) ClosedChan ¶
func (s *Socket) ClosedChan() ClosedChan
ClosedChan returns a channel which is closed as soon as the socket is closed. This method is thread-safe.
func (*Socket) IsClosed ¶
IsClosed returns a boolean indicating if the socket connection is closed. This method is thread-safe.
func (*Socket) OnClose ¶
func (s *Socket) OnClose(f OnCloseFunc)
OnClose triggers the function as soon as the connection closes. This method can be called multiple times to bind multiple functions. This method is thread-safe.
func (*Socket) Ready ¶
func (s *Socket) Ready()
Ready signalizes the Socket that the initialization is done. The socket starts reading from the underlying connection. This should be only called once per socket.
func (*Socket) RegisterFunc ¶
RegisterFunc registers a remote function. This method is thread-safe.
func (*Socket) RegisterFuncs ¶
RegisterFuncs registers a map of remote functions. This method is thread-safe.
func (*Socket) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Socket) SetCallHook ¶
SetCallHook sets the call hook function which is triggered, if a local remote callable function will be called. This hook can be used for logging purpose. Only set this hook during initialization.
func (*Socket) SetCallTimeout ¶
SetCallTimeout sets the timeout for call requests. Only set this during initialization.
func (*Socket) SetErrorHook ¶
SetErrorHook sets the error hook function which is triggered, if a local remote callable function returns an error. This hook can be used for logging purpose. Only set this hook during initialization.
func (*Socket) SetMaxMessageSize ¶
SetMaxMessageSize sets the maximum message size in bytes. Only set this during initialization.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package codec contains sub-packages with different codecs that can be used to encode and decode the PAKT messages.
|
Package codec contains sub-packages with different codecs that can be used to encode and decode the PAKT messages. |
sample
|
|