Documentation ¶
Index ¶
- Variables
- func StructHandler(s interface{}) map[string]StreamHandler
- type Client
- type ClientConnection
- type Config
- type Connection
- type ConnectionState
- type Decoder
- type DecodingProvider
- type Encoder
- type Encoding
- type EncodingProvider
- type ErrorPropagationReader
- type ErrorPropagationWriter
- type Network
- type Rpc
- type RpcConnectionError
- type RpcError
- type RpcStatusCode
- type Server
- type ServerConnection
- type StickyConnection
- func (sc *StickyConnection) Call(ctx context.Context, path string, req interface{}, res interface{}) error
- func (sc *StickyConnection) CallStream(ctx context.Context, path string, req interface{}) (StreamReader, error)
- func (sc *StickyConnection) Id() string
- func (sc *StickyConnection) LocalAddr() net.Addr
- func (sc *StickyConnection) OpenStream(ctx context.Context, path string) (Stream, error)
- func (sc *StickyConnection) ProcessStream(ctx context.Context, path string, req interface{}, ...) error
- func (sc *StickyConnection) RemoteAddr() net.Addr
- func (sc *StickyConnection) State() StickyConnectionState
- func (sc *StickyConnection) Terminate()
- type StickyConnectionState
- type Stream
- type StreamHandler
- type StreamImpl
- type StreamReader
- type StreamWriter
- type TcpNetwork
- type TlsNetwork
- type Transport
- func (transport *Transport) AcceptStream(ctx context.Context) (Stream, error)
- func (transport *Transport) Call(ctx context.Context, path string, req interface{}, response interface{}) error
- func (transport *Transport) CallStream(ctx context.Context, path string, req interface{}) (StreamReader, error)
- func (transport *Transport) Close() error
- func (transport *Transport) Config() *Config
- func (transport *Transport) LocalAddr() net.Addr
- func (transport *Transport) OpenStream(ctx context.Context, path string) (Stream, error)
- func (transport *Transport) RemoteAddr() net.Addr
Constants ¶
This section is empty.
Variables ¶
var DEFAULT_CONFIG = &Config{ KeepAliveTimeout: 40 * time.Second, KeepAliveInterval: 20 * time.Second, Timeout: 1 * time.Minute, }
var GobEncoding = &Encoding{Encoder: func(writer io.Writer) Encoder { return &gobEncoder{gob.NewEncoder(&ErrorPropagationWriter{Writer: writer})} }, Decoder: func(reader io.Reader) Decoder { return &gobDecoder{gob.NewDecoder(&ErrorPropagationReader{Reader: reader})} }, Register: func(dataType interface{}) { gob.Register(dataType) }}
Functions ¶
func StructHandler ¶
func StructHandler(s interface{}) map[string]StreamHandler
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
type ClientConnection ¶
type Config ¶
type Connection ¶
type ConnectionState ¶
type ConnectionState int
const ( CON_CONNECTING ConnectionState = iota CON_READY CON_FAILURE CON_IDLE CON_CLOSED )
type Decoder ¶
type Decoder interface {
Decode(to interface{}) error
}
Must return RpcError(code=RPC_WRONG_ENCODING) or RpcConnectionError on underlying reader/writer errors
type DecodingProvider ¶
type Encoder ¶
type Encoder interface {
Encode(from interface{}) error
}
Must return RpcError(code=RPC_WRONG_ENCODING) or RpcConnectionError on underlying reader/writer errors
type Encoding ¶
type Encoding struct { Encoder EncodingProvider Decoder DecodingProvider Register func(dataType interface{}) }
type EncodingProvider ¶
type ErrorPropagationReader ¶
type ErrorPropagationWriter ¶
Used to propagate writer errors as RpcError to distinguish encoding errors from connection errors
type RpcConnectionError ¶
type RpcConnectionError struct {
Cause error
}
func (*RpcConnectionError) Error ¶
func (rce *RpcConnectionError) Error() string
type RpcError ¶
type RpcError struct { Code RpcStatusCode Msg string }
RPC error is part of rpc protocol error reporting. All these errors is fatal for stream - stream will be closed after such error
type RpcStatusCode ¶
type RpcStatusCode byte
const ( RPC_OK RpcStatusCode = iota RPC_PROTOCOL_ERROR // wrong protocol; followed by error message and stream close RPC_NOT_FOUND // received by client if not such path; like Http 404; followed by stream close RPC_WRONG_ENCODING // returned to client when server unable to decode stream message; followed by encoded string with error description and stream close RPC_APP_ERROR // application specific error; followed by encoded app error object and stream close )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) RegisterHandler ¶
func (s *Server) RegisterHandler(path string, handler StreamHandler)
type ServerConnection ¶
type ServerConnection interface { Connection AcceptStream(ctx context.Context) (Stream, error) }
type StickyConnection ¶
type StickyConnection struct { StateChangeListener func(oldState StickyConnectionState, newState StickyConnectionState) // contains filtered or unexported fields }
func (*StickyConnection) Call ¶
func (sc *StickyConnection) Call(ctx context.Context, path string, req interface{}, res interface{}) error
func (*StickyConnection) CallStream ¶
func (sc *StickyConnection) CallStream(ctx context.Context, path string, req interface{}) (StreamReader, error)
func (*StickyConnection) Id ¶
func (sc *StickyConnection) Id() string
func (*StickyConnection) LocalAddr ¶
func (sc *StickyConnection) LocalAddr() net.Addr
func (*StickyConnection) OpenStream ¶
func (*StickyConnection) ProcessStream ¶
func (*StickyConnection) RemoteAddr ¶
func (sc *StickyConnection) RemoteAddr() net.Addr
func (*StickyConnection) State ¶
func (sc *StickyConnection) State() StickyConnectionState
func (*StickyConnection) Terminate ¶
func (sc *StickyConnection) Terminate()
Terminate connection. It can't be used after termination and can be freely deleted
type StickyConnectionState ¶
type StickyConnectionState uint8
const ( SCON_OFFLINE StickyConnectionState = iota // all calls will return error in this state, can become online when underlying transport reconnected SCON_ONLINE // underlying transport is connected and can be used SCON_TERMINATED // connection terminated and can't be used anymore )
type StreamHandler ¶
func FuncHandler ¶
func FuncHandler(f interface{}) StreamHandler
type StreamImpl ¶
type StreamImpl struct {
// contains filtered or unexported fields
}
Stream is analogue of tpc connection but it opened on multiplexed tcp stream
func (*StreamImpl) Close ¶
func (s *StreamImpl) Close() error
func (*StreamImpl) Path ¶
func (s *StreamImpl) Path() string
func (*StreamImpl) Read ¶
func (s *StreamImpl) Read(target interface{}) error
func (*StreamImpl) Write ¶
func (s *StreamImpl) Write(data interface{}) error
func (*StreamImpl) WriteError ¶
func (s *StreamImpl) WriteError(err error) error
type StreamReader ¶
restricted interface to read messages from stream note what closing reader or writer will cause whole stream to be closed, not only single direction as in TCP
type StreamWriter ¶
restricted interface to write messages to stream
type TlsNetwork ¶
func (*TlsNetwork) DialContext ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport allow open and accept streams. Transport is not statefull and can fail. Client/Server implementation support creating and maintaining transports(including reconnects) This particular implementation is around multiplexed TCP/TLS connection
func (*Transport) AcceptStream ¶
Block until other side opens stream. Client can validate path and send error RPC_NOT_FOUND if path is bad
func (*Transport) Call ¶
func (transport *Transport) Call(ctx context.Context, path string, req interface{}, response interface{}) error
Simplified method with call semantic. Uses openStream, write request and read response after what closes the stream. Should always have request and response. If nil passed to req or res bool placeholder will be used instead.
func (*Transport) CallStream ¶
func (transport *Transport) CallStream(ctx context.Context, path string, req interface{}) (StreamReader, error)
Simplified method with call semantic. Uses openStream, write request and return reader to read sequence of responses. User must close reader after completion.
func (*Transport) OpenStream ¶
Open stream for specified path. Stream operations can be canceled via ctx
func (*Transport) RemoteAddr ¶
Return remote address of the transport connection