bitmonster

package module
v0.0.0-...-ea08b5a Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2017 License: GPL-3.0 Imports: 19 Imported by: 0

README

BitMonster - A Monster handling your Bits

BitMonster Logo

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

This project is deprecated. Use PROTON.

Documentation

Overview

Package bitmonster - A Monster handling your Bits

Index

Constants

View Source
const (
	// InterruptExitCode is the application error exit code.
	InterruptExitCode = 5
)

Variables

View Source
var (
	ErrNoContextData = errors.New("no context data available to decode")
)

Functions

func CheckOrigin

func CheckOrigin(r *http.Request) bool

CheckOrigin returns true if the request Origin header is acceptable. Returns true if the origin is set and is equal to the request host. If the AllowOrigin hosts are set in the settings, then this origin has to match one of those.

func Fatal

func Fatal(err error)

Fatal logs the error and exits the application if the passed error is not nil.

func Init

func Init() error

Init initializes the BitMonster runtime and connects to the database.

func OffCloseSocket

func OffCloseSocket(f OnNewSocketFunc)

OffCloseSocket remove the event listener again.

func OffNewSocket

func OffNewSocket(f OnNewSocketFunc)

OffNewSocket remove the event listener again.

func OnCloseSocket

func OnCloseSocket(f OnNewSocketFunc)

OnCloseSocket is triggered if a socket connection is closed.

func OnInit

func OnInit(f func())

OnInit is triggered during the BitMonster initialization process.

func OnNewSocket

func OnNewSocket(f OnNewSocketFunc)

OnNewSocket is triggered during each new socket connection.

func ReleasedChan

func ReleasedChan() <-chan struct{}

ReleasedChan returns a blocking read-only channel which is closed (non-blocking) during the application shutdown.

func Run

func Run() error

Run starts the BitMonster server. This method is blocking.

Types

type ClosedChan

type ClosedChan <-chan struct{}

ClosedChan is a channel which doesn't block as soon as the socket is closed.

type Context

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

A Context contains the function call context with the passed parameters and the registered callbacks.

func (*Context) ClearValues

func (c *Context) ClearValues()

ClearValues clears all values from the custom values map. This operation is thread-safe.

func (*Context) Data

func (c *Context) Data(d interface{})

Data sets the data value which is passed finally to the client.

func (*Context) Decode

func (c *Context) 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 (*Context) DeleteValue

func (c *Context) DeleteValue(key interface{})

DeleteValue removes a custom value with a key. This operation is thread-safe.

func (*Context) Error

func (c *Context) Error(msg string)

Error sets the error message which is passed to the error callback. Once called, the error callback will always be called on the client-side if it is defined.

func (*Context) HasError

func (c *Context) HasError() bool

HasError returns a boolean whenever the context error was set.

func (*Context) Module

func (c *Context) Module() *Module

Module returns the module of the context.

func (*Context) SetValue

func (c *Context) SetValue(key interface{}, value interface{})

SetValue sets a custom value with a key. This operation is thread-safe.

func (*Context) Socket

func (c *Context) Socket() *Socket

Socket returns the socket of the context.

func (*Context) Value

func (c *Context) 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.

type Event

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

An Event implements a single BitMonster event to trigger attached listeners.

func (*Event) Name

func (e *Event) Name() string

Name returns the event name.

func (*Event) Trigger

func (e *Event) Trigger(data ...interface{}) error

Trigger the event and pass optional one variadic parameter value.

func (*Event) TriggerSocket

func (e *Event) TriggerSocket(socket *Socket, data ...interface{}) error

TriggerSocket triggers the event only for the specified socket. Pass optional one variadic parameter value.

func (*Event) TriggerSockets

func (e *Event) TriggerSockets(sockets []*Socket, data ...interface{}) error

TriggerSockets triggers the event only for the specified sockets. Pass optional one variadic parameter value.

type Hook

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

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

type Method

type Method func(*Context) error

A Method is a module method. If an error is returned, the error callback on the client side is triggered.

type MethodMap

type MethodMap map[string]Method

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, error)

NewModule creates and register a new BitMonster Module. This method is not thread-safe and should be called only during application initialization.

func (*Module) AddEvent

func (m *Module) AddEvent(name string, hooks ...Hook) *Event

AddEvent adds and registers a new event. The newly created event is returned.

func (*Module) AddMethod

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

AddMethod adds a method which is callable from the client-side. Optionally pass hooks which are processed before. This method is not thread-safe and should be only called during module initialization.

func (*Module) AddMethods

func (m *Module) AddMethods(methodsMap MethodMap, hooks ...Hook)

AddMethods adds the methods in the methods map. Optionally pass hooks which are processed before. This method is not thread-safe and should be only called during module initialization.

func (*Module) Event

func (m *Module) Event(name string) (*Event, error)

Event returns the event specified by the name.

func (*Module) Name

func (m *Module) Name() string

Name returns the module's name.

type OnCloseSocketFunc

type OnCloseSocketFunc func(s *Socket)

OnCloseSocketFunc is an event function.

type OnNewSocketFunc

type OnNewSocketFunc func(s *Socket)

OnNewSocketFunc is an event function.

type Socket

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

A Socket is a BitMonster socket.

func GetSocket

func GetSocket(id string) *Socket

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

func (*Socket) Check

func (s *Socket) Check()

Check triggeres an internal check routine. Event hooks of already bound events are rerun. Trigger this, if an important state of the socket session has changed and event hooks should be rerun. (Example: logout)

func (*Socket) Close

func (s *Socket) Close()

Close the socket connection.

func (*Socket) ClosedChan

func (s *Socket) ClosedChan() ClosedChan

ClosedChan returns a channel which is non-blocking (closed) as soon as the socket is closed.

func (*Socket) DeleteValue

func (s *Socket) DeleteValue(key interface{})

DeleteValue removes a custom value with a key. This operation is thread-safe.

func (*Socket) DeleteValueAfterTimeout

func (s *Socket) DeleteValueAfterTimeout(key interface{}, timeout time.Duration)

DeleteValueAfterTimeout removes a custom value after the specified timeout. Previously set timeouts for the same key are stopped. This operation is thread-safe.

func (*Socket) ID

func (s *Socket) ID() string

ID returns the socket's unique ID. This is a cryptographically secure pseudorandom number.

func (*Socket) IsClosed

func (s *Socket) IsClosed() bool

IsClosed returns a boolean whenever the connection is closed.

func (*Socket) OffClose

func (s *Socket) OffClose(f OnNewSocketFunc)

OffClose removea the event listener again.

func (*Socket) OnClose

func (s *Socket) OnClose(f OnCloseSocketFunc)

OnClose sets the functions which is triggered if the socket connection is closed.

func (*Socket) RemoteAddr

func (s *Socket) RemoteAddr() string

RemoteAddr returns the remote address of the client.

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

func (s *Socket) UserAgent() string

UserAgent returns the user agent of the client.

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
changefeeds
Package changefeeds provides the database change events for the auth package.
Package changefeeds provides the database change events for the auth package.
Log backend used by the BitMonster library.
Log backend used by the BitMonster library.
Package settings handles the BitMonster settings.
Package settings handles the BitMonster settings.
Package utils - BitMonster utilities Package utils - BitMonster utilities
Package utils - BitMonster utilities Package utils - BitMonster utilities

Jump to

Keyboard shortcuts

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