proton

package module
v0.0.0-...-16c3cf3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2019 License: GPL-3.0 Imports: 20 Imported by: 0

README

Proton - A powerful platform for your real-time web applications

Proton is a powerful platform for your real-time mobile or web application.

This project is no longer being under active development. Maybe it will continue in the future

Protocol Specification

See the protocol specification.

Documentation

Overview

Package proton - A powerful platform for your real-time web applications

Index

Constants

View Source
const (
	// ProtocolVersion defines the protocol version defined in the specifications.
	ProtocolVersion byte = 0
)

Variables

View Source
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")
)
View Source
var (
	// Log is the public logrus value used internally.
	Log = logrus.New()
)

Functions

func Error

func Error(response string, err error) 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

func (c *C) Decode(v interface{}) error

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

func (c *C) DecodeHeader(key string, v interface{}) error

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.

func (*C) Module

func (c *C) Module() *Module

Module returns the module of the context.

func (*C) Response

func (c *C) Response(d interface{})

Response sets the response data value which is passed to the client.

func (*C) Socket

func (c *C) Socket() *Socket

Socket returns the socket of the context.

type Hook

type Hook interface {
	Hook(c *C) error
}

A Hook is executed before the actual Module Method or Event.

type Hooks

type Hooks []Hook

A Hooks slice.

type Method

type Method func(*C) error

A Method is a module method callable from the peer.

type Methods

type Methods map[string]Method

Methods is a collection of methods.

type Module

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

A Module contains and handles methods and events.

func NewModule

func NewModule(name string) *Module

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

func (m *Module) AddMethod(name string, hooks Hooks, method Method)

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

func (m *Module) AddMethods(hooks Hooks, methods Methods)

AddMethods adds multiple methods and behaves like AddMethod. This method is not thread-safe and should be only called during module initialization.

func (*Module) Name

func (m *Module) Name() string

Name returns the module's name.

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 NewServer

func NewServer(opts ...*Options) *Server

NewServer creates a new server instance. Optionally pass the server options.

func (*Server) AddModule

func (s *Server) AddModule(m *Module)

AddModule registers a module to the server. This method is not thread-safe and should be only called during initialization.

func (*Server) Close

func (s *Server) Close() error

Close the server by blocking all new incoming connections. This does not close the http server.

func (*Server) GetSocket

func (s *Server) GetSocket(id string) (so *Socket)

GetSocket obtains a socket by its ID. Returns nil if not found.

func (*Server) IsClosed

func (s *Server) IsClosed() bool

IsClosed returns a boolean indicating if the server is closed. This does not indicate the http server state.

func (*Server) OffNewSocket

func (s *Server) OffNewSocket(f func(s *Socket))

OffNewSocket remove the event listener again.

func (*Server) OnNewSocket

func (s *Server) OnNewSocket(f func(s *Socket))

OnNewSocket is triggered during each new socket connection.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the HTTP Handler interface of the http package.

func (*Server) Sockets

func (s *Server) Sockets() []*Socket

Sockets returns a list of all current connected sockets.

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) Close

func (s *Socket) Close() error

Close the socket connection. This method is thread-safe.

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) ID

func (s *Socket) ID() string

ID returns the socket ID.

func (*Socket) IsClosed

func (s *Socket) IsClosed() bool

IsClosed returns a boolean indicating if the socket connection is closed. This method is thread-safe.

func (*Socket) LocalAddr

func (s *Socket) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Socket) RemoteAddr

func (s *Socket) RemoteAddr() net.Addr

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.

Directories

Path Synopsis
1 command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL