Documentation
¶
Index ¶
- Variables
- type CallFunc
- type Config
- type Conn
- type Data
- type Error
- type ErrorCode
- type Hook
- type Listener
- type Server
- type ServerConfig
- type ServerHandler
- type Session
- func (s *Session) Call(ctx context.Context, service, id string, data interface{}) (d *Data, err error)
- func (s *Session) CallAsync(ctx context.Context, service, id string, data interface{}) (d *Data, err error)
- func (s *Session) CallTimeout() time.Duration
- func (s *Session) Codec() codec.Codec
- func (s *Session) DeleteValue(k string)
- func (s *Session) ID() string
- func (s *Session) LocalAddr() net.Addr
- func (s *Session) OpenStream(ctx context.Context, service, id string) (stream Stream, err error)
- func (s *Session) RegisterCall(service, id string, f CallFunc)
- func (s *Session) RegisterStream(service, id string, f StreamFunc)
- func (s *Session) RemoteAddr() net.Addr
- func (s *Session) SetValue(k string, v interface{})
- func (s *Session) Value(k string) (v interface{})
- type SessionHandler
- type Stream
- type StreamFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed defines the error if a stream is unexpectedly closed. ErrClosed = errors.New("closed") // ErrInvalidVersion defines the error if the version of both peers do not match // during the version exchange. ErrInvalidVersion = errors.New("invalid version") )
var ( // ErrNoData defines the error if no data is available. ErrNoData = errors.New("no data available to decode") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Log *zerolog.Logger
Codec codec.Codec
PrintPanicStackTraces bool
SendErrToCaller bool
// InitTimeout specifies the connection initialization timeout.
InitTimeout time.Duration
// CallTimeout specifies the default timeout for any Call.
// This value can be overridden per call in the .orbit file.
// A value < 0 means no timeout.
// A value of 0 will take the default call timeout value.
CallTimeout time.Duration
}
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a config, where all fields are set to their default values.
type Conn ¶
type Conn interface {
closer.Closer
// AcceptStream returns the next stream opened by the peer, blocking until one is available.
AcceptStream(context.Context) (Stream, error)
// OpenStream opens a new bidirectional stream.
// There is no signaling to the peer about new streams:
// The peer can only accept the stream after data has been sent on the stream.
OpenStream(context.Context) (Stream, error)
// LocalAddr returns the local address.
LocalAddr() net.Addr
// RemoteAddr returns the address of the peer.
RemoteAddr() net.Addr
}
type Data ¶
type Data struct {
// Raw is the byte representation of the encoded data.
Raw []byte
// contains filtered or unexported fields
}
type Error ¶
type Error interface {
// Embeds the standard go error interface.
error
// Msg returns a textual explanation of the error and should
// NOT contain sensitive information about the application.
Msg() string
// Code returns an integer that can give a hint about the
// type of error that occurred.
Code() int
}
An Error offers a way for handler functions of control calls to determine the information passed to the client, in case an error occurs. That way, sensitive information that may be contained in a standard error, can be hidden from the client. Instead, a Msg and a code can be sent back to give a non-sensitive explanation of the error and a code that is easy to check, to allow handling common errors.
type ErrorCode ¶
type ErrorCode struct {
// The code is used to identify common errors.
Code int
// contains filtered or unexported fields
}
The ErrorCode type extends the standard go error by a simple integer code. It is returned in the Call- functions of this package and allows callers that use them to check for common errors via the code.
type Hook ¶
type Hook interface {
// Called after the session has established a first stream and
// performed the handshake.
// If the returned err != nil, the new session is closed immediately.
OnNewSession(s *Session, stream Stream) error
// todo:
// If the returned err != nil, the call is aborted.
OnCall(s *Session, service, id string) error
// todo:
// If err == nil, then the call completed successfully.
OnCallCompleted(s *Session, service, id string, err error)
// If the returned err != nil, the stream is aborted.
OnNewStream(s *Session, service, id string) error
}
Hook allows third-party code to hook into orbit's logic, to implement for example logging or authentication functionality. Hooks that return an error have the capability to abort the action that triggered them. E.g. if OnNewSession() returns a non-nil error, the session will be closed.
type Server ¶
Server implements a simple orbit server.
func NewServer ¶
func NewServer(ln Listener, cf *ServerConfig, h ServerHandler, hs ...Hook) *Server
NewServer creates a new orbit server. A listener is required the server will use to listen for incoming connections. A config can be provided, where every property of it that has not been set will be initialized with a default value. That makes it possible to overwrite only the interesting properties for the caller.
func (*Server) Listen ¶
Listen listens for new socket connections, which it passes to the new connection channel that is read by the server workers. This method is blocking.
type ServerConfig ¶
type ServerConfig struct {
*Config
// The number of goroutines that handle incoming connections on the server.
// If not set, defaults to defaultNewConnNumberWorkers.
NewConnNumberWorkers int
// The size of the channel on which new connections are passed to the
// server workers.
// Should not be less than NewConnNumberWorkers.
// If not set, defaults to defaultNewConnChanSize.
NewConnChanSize int
// The size of the channel on which new server sessions are passed into,
// so that a user of this package can read them from it.
// Should not be less than NewConnNumberWorkers.
// If not set, defaults to defaultNewSessionChanSize.
NewSessionChanSize int
}
type ServerHandler ¶
type ServerHandler interface {
SessionHandler
InitServer(s *Server)
}
type Session ¶
func (*Session) CallTimeout ¶
CallTimeout returns the default timeout for all calls.
func (*Session) DeleteValue ¶
DeleteValue deletes the value for the key k in the values map. If the key does not exist, this is a no-op.
func (*Session) OpenStream ¶
OpenStream opens a new stream with the given channel ID.
func (*Session) RegisterCall ¶
func (*Session) RegisterStream ¶
func (s *Session) RegisterStream(service, id string, f StreamFunc)
func (*Session) RemoteAddr ¶
RemoteAddr returns the remote network address.
type SessionHandler ¶
type SessionHandler interface {
InitSession(s *Session)
}