Documentation ¶
Overview ¶
Package bitmonster - A Monster handling your Bits
Index ¶
- Constants
- Variables
- func CheckOrigin(r *http.Request) bool
- func Fatal(err error)
- func Init() error
- func OffCloseSocket(f OnNewSocketFunc)
- func OffNewSocket(f OnNewSocketFunc)
- func OnCloseSocket(f OnNewSocketFunc)
- func OnInit(f func())
- func OnNewSocket(f OnNewSocketFunc)
- func ReleasedChan() <-chan struct{}
- func Run() error
- type ClosedChan
- type Context
- func (c *Context) ClearValues()
- func (c *Context) Data(d interface{})
- func (c *Context) Decode(v interface{}) error
- func (c *Context) DeleteValue(key interface{})
- func (c *Context) Error(msg string)
- func (c *Context) HasError() bool
- func (c *Context) Module() *Module
- func (c *Context) SetValue(key interface{}, value interface{})
- func (c *Context) Socket() *Socket
- func (c *Context) Value(key interface{}, f ...func() interface{}) interface{}
- type Event
- type Hook
- type Method
- type MethodMap
- type Module
- type OnCloseSocketFunc
- type OnNewSocketFunc
- type Socket
- func (s *Socket) Check()
- func (s *Socket) Close()
- func (s *Socket) ClosedChan() ClosedChan
- func (s *Socket) DeleteValue(key interface{})
- func (s *Socket) DeleteValueAfterTimeout(key interface{}, timeout time.Duration)
- func (s *Socket) ID() string
- func (s *Socket) IsClosed() bool
- func (s *Socket) OffClose(f OnNewSocketFunc)
- func (s *Socket) OnClose(f OnCloseSocketFunc)
- func (s *Socket) RemoteAddr() string
- func (s *Socket) SetValue(key interface{}, value interface{})
- func (s *Socket) UserAgent() string
- func (s *Socket) Value(key interface{}, f ...func() interface{}) interface{}
Constants ¶
const (
// InterruptExitCode is the application error exit code.
InterruptExitCode = 5
)
Variables ¶
var (
ErrNoContextData = errors.New("no context data available to decode")
)
Functions ¶
func CheckOrigin ¶
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 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.
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 ¶
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 ¶
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) SetValue ¶
func (c *Context) SetValue(key interface{}, value interface{})
SetValue sets a custom value with a key. This operation is thread-safe.
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) TriggerSocket ¶
TriggerSocket triggers the event only for the specified socket. Pass optional one variadic parameter value.
func (*Event) TriggerSockets ¶
TriggerSockets triggers the event only for the specified sockets. Pass optional one variadic parameter value.
type Method ¶
A Method is a module method. If an error is returned, the error callback on the client side is triggered.
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 BitMonster Module. This method is not thread-safe and should be called only during application initialization.
func (*Module) AddEvent ¶
AddEvent adds and registers a new event. The newly created event is returned.
func (*Module) AddMethod ¶
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 ¶
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.
type OnCloseSocketFunc ¶
type OnCloseSocketFunc func(s *Socket)
OnCloseSocketFunc is an event function.
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
A Socket is a BitMonster socket.
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) 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 ¶
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 ¶
ID returns the socket's unique ID. This is a cryptographically secure pseudorandom number.
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 ¶
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) 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.
Source Files ¶
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 |