Documentation
¶
Overview ¶
Package proton - A powerful platform for your real-time web applications
Index ¶
- Constants
- Variables
- func Error(response string, err error) error
- func Run(s *Server, opts ...*RunOptions) error
- type C
- type Hook
- type Hooks
- type Method
- type Methods
- type Module
- type Options
- type RunOptions
- type Server
- func (s *Server) AddModule(m *Module)
- func (s *Server) Close() error
- func (s *Server) GetSocket(id string) (so *Socket)
- func (s *Server) IsClosed() bool
- func (s *Server) OffNewSocket(f func(s *Socket))
- func (s *Server) OnNewSocket(f func(s *Socket))
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Sockets() []*Socket
- type Socket
- func (s *Socket) Close() error
- func (s *Socket) ClosedChan() <-chan struct{}
- func (s *Socket) DeleteValue(key interface{})
- func (s *Socket) ID() string
- func (s *Socket) IsClosed() bool
- func (s *Socket) LocalAddr() net.Addr
- func (s *Socket) RemoteAddr() net.Addr
- func (s *Socket) SetValue(key interface{}, value interface{})
- func (s *Socket) Value(key interface{}, f ...func() interface{}) interface{}
Constants ¶
const ( // ProtocolVersion defines the protocol version defined in the specifications. ProtocolVersion byte = 0 )
Variables ¶
var ( // ErrClosed defines the error if the connection was closed. ErrClosed = errors.New("closed") // ErrNoContextData defines the error if no context data was set. ErrNoContextData = errors.New("no context data available to decode") // ErrNoHeaderData defines the error if no header data was set. ErrNoHeaderData = errors.New("no header data available to decode") // ErrMaxMsgSizeExceeded if the maximum message payload size is exceeded. ErrMaxMsgSizeExceeded = errors.New("maximum message size exceeded") )
var ( // Log is the public logrus value used internally. Log = logrus.New() )
Functions ¶
func Error ¶
Error creates a new response error. The response is the error message send to the client.
func Run ¶
func Run(s *Server, opts ...*RunOptions) error
Run is a shorthand to configure and start the HTTP server. It also handles termination requests and graceful shutdowns.
Types ¶
type C ¶
type C struct {
// Data is the raw byte representation of the encoded context data.
Data []byte
// Header contains the raw header bytes attached to the request.
Header map[string][]byte
// A map to hold custom data values.
// Commonly used by hooks.
Values map[interface{}]interface{}
// contains filtered or unexported fields
}
C defines the current call context with the passed data and the registered callbacks.
func (*C) Decode ¶
Decode the context data to a custom value. The value has to be passed as pointer. Returns ErrNoContextData if there is no context data available to decode.
func (*C) DecodeHeader ¶
DecodeHeader decodes the given header data specified by its key to a custom value. The value has to be passed as pointer. Returns ErrNoHeaderData if no header data was found by the key.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
A Module contains and handles methods and events.
func NewModule ¶
NewModule creates and register a new Proton Module. This method is not thread-safe and should be called only during application initialization.
func (*Module) AddMethod ¶
AddMethod adds a method which is callable from the client-side. Hooks are processed before the method and are capable to terminate the call. This method is not thread-safe and should be only called during module initialization.
func (*Module) AddMethods ¶
AddMethods adds multiple methods and behaves like AddMethod. This method is not thread-safe and should be only called during module initialization.
type Options ¶
type Options struct {
// ReadBufferSize and WriteBufferSize specify I/O buffer sizes. If a buffer
// size is zero, then a default value of 4096 is used. The I/O buffer sizes
// do not limit the size of the messages that can be sent or received.
ReadBufferSize, WriteBufferSize int
// MaxMessageSize defines the maximum message payload size in bytes.
MaxMessageSize int
// CheckOrigin returns true if the request Origin header is acceptable. If
// CheckOrigin is nil, the host in the Origin header must not be set or
// must match the host of the request.
// This method is used by the backend sockets before establishing connections.
CheckOrigin func(r *http.Request) bool
}
Options define the BinarySocket optional options.
type RunOptions ¶
type RunOptions struct {
// ListenAddr for the HTTP server.
ListenAddr string
// HandleURL for the proton server.
HandleURL string
// FileServer defines a map of urls mapped to directory paths.
FileServer map[string]string
// DisableInterrupts disables the interrupt handler.
DisableInterrupts bool
}
RunOptions for Run.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements the web server which handles the Proton clients.
func (*Server) AddModule ¶
AddModule registers a module to the server. This method is not thread-safe and should be only called during initialization.
func (*Server) Close ¶
Close the server by blocking all new incoming connections. This does not close the http server.
func (*Server) IsClosed ¶
IsClosed returns a boolean indicating if the server is closed. This does not indicate the http server state.
func (*Server) OffNewSocket ¶
OffNewSocket remove the event listener again.
func (*Server) OnNewSocket ¶
OnNewSocket is triggered during each new socket connection.
type Socket ¶
type Socket struct {
// V is a custom value which can be set.
V interface{}
// contains filtered or unexported fields
}
Socket defines the Proton socket implementation.
func (*Socket) ClosedChan ¶
func (s *Socket) ClosedChan() <-chan struct{}
ClosedChan returns a channel which is closed as soon as the socket is closed. This method is thread-safe.
func (*Socket) DeleteValue ¶
func (s *Socket) DeleteValue(key interface{})
DeleteValue removes a custom value with a key. This operation is thread-safe.
func (*Socket) IsClosed ¶
IsClosed returns a boolean indicating if the socket connection is closed. This method is thread-safe.
func (*Socket) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Socket) SetValue ¶
func (s *Socket) SetValue(key interface{}, value interface{})
SetValue sets a custom value with a key. This operation is thread-safe.
func (*Socket) Value ¶
func (s *Socket) Value(key interface{}, f ...func() interface{}) interface{}
Value returns a custom value previously set by the key. Returns nil if it does not exists. One variadic function is called if no value exists for the given key. The return value of this function is the new value for the key. This operation is thread-safe.