Documentation
¶
Index ¶
- func CreateHandlerFor[T any](instance *Instance, action string, handler func(*Context, T) pipes.Event)
- func DefaultClientEncodingMiddleware(client *Client, message []byte) ([]byte, error)
- func DefaultDecodingMiddleware(client *Client, bytes []byte) ([]byte, error)
- func ErrorResponse(ctx *Context, message localization.Translations, err error) pipes.Event
- func NormalResponse(ctx *Context, data map[string]interface{}) pipes.Event
- func Response(ctx *Context, data map[string]interface{}, instance *Instance) pipes.Event
- func SuccessResponse(ctx *Context) pipes.Event
- func Translate(c *Context, message localization.Translations) string
- type Client
- type Config
- type ConnectionTokenClaims
- type Context
- type Instance
- func (instance *Instance) AddClient(client Client) *Client
- func (instance *Instance) CheckToken(token string, local *pipes.LocalNode) (*ConnectionTokenClaims, bool)
- func (instance *Instance) Disconnect(id string, session string)
- func (instance *Instance) ExistsConnection(id string, session string) bool
- func (instance *Instance) GenerateToken(account string, session string, extra string, node uint) (string, error)
- func (instance *Instance) Get(id string, session string) (*Client, bool)
- func (instance *Instance) GetConnections(id string) int
- func (instance *Instance) GetSessions(id string) []string
- func (instance *Instance) Handle(ctx *Context) bool
- func (instance *Instance) Remove(id string, session string)
- func (instance *Instance) ReportClientError(client *Client, context string, err error)
- func (instance *Instance) ReportGeneralError(context string, err error)
- func (instance *Instance) Send(id string, msg []byte)
- func (instance *Instance) SendEventToOne(c *Client, event pipes.Event) error
- func (instance *Instance) SendMessage(client *Client, msg []byte) error
- func (instance *Instance) SendSession(id string, session string, msg []byte) bool
- func (instance *Instance) SetupConnectionsCache(expected int64)
- func (instance *Instance) UpdateClient(client *Client)
- type Message
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateHandlerFor ¶
func CreateHandlerFor[T any](instance *Instance, action string, handler func(*Context, T) pipes.Event)
Create a handler for an action using generics (with parsing already implemented)
func DefaultClientEncodingMiddleware ¶
Default pipes-fiber encoding middleware (using JSON)
func DefaultDecodingMiddleware ¶
Default pipes-fiber decoding middleware (using JSON)
func ErrorResponse ¶
func ErrorResponse(ctx *Context, message localization.Translations, err error) pipes.Event
func SuccessResponse ¶
func Translate ¶
func Translate(c *Context, message localization.Translations) string
Translate any message on a request
Types ¶
type Client ¶
type Config ¶
type Config struct {
ExpectedConnections int64
SessionDuration time.Duration // How long a session should stay alive
Secret []byte // JWT secret (for authorization)
// Node handlers
NodeDisconnectHandler func(node pipes.Node)
// Client handlers
ClientDisconnectHandler func(client *Client)
TokenValidateHandler func(claims *ConnectionTokenClaims, attachments string) bool // Called before the websocket connection is accepted, returns if the client should be disconnected (true = disconnect)
ClientConnectHandler func(client *Client, attachments string) bool // Called after websocket connection is established, returns if the client should be disconnected (true = disconnect)
ClientEnterNetworkHandler func(client *Client, attachments string) bool // Called after pipes adapter is registered, returns if the client should be disconnected (true = disconnect)
// Codec middleware
ClientEncodingMiddleware func(client *Client, instance *Instance, message []byte) ([]byte, error)
DecodingMiddleware func(client *Client, instance *Instance, message []byte) ([]byte, error)
// Error handler
ErrorHandler func(err error)
}
! If the functions aren't implemented pipesfiber will panic
type ConnectionTokenClaims ¶
type ConnectionTokenClaims struct {
Account string `json:"acc"` // Account id of the connecting client
ExpiredUnixSec int64 `json:"e_u"` // Expiration time in unix seconds
Session string `json:"ses"` // Session id of the connecting client
Node string `json:"node"` // Node id of the node the client is connecting to
Extra string `json:"extra,omitempty"` // Extra arguments for the connection
jwt.RegisteredClaims
}
Connection token struct
type Instance ¶
type Instance struct {
Config Config
// contains filtered or unexported fields
}
func (*Instance) CheckToken ¶
func (instance *Instance) CheckToken(token string, local *pipes.LocalNode) (*ConnectionTokenClaims, bool)
Check the JWT token
func (*Instance) Disconnect ¶
Disconnect a client from the network
func (*Instance) ExistsConnection ¶
func (*Instance) GenerateToken ¶
func (instance *Instance) GenerateToken(account string, session string, extra string, node uint) (string, error)
Generate a connection token for a node
func (*Instance) GetConnections ¶
func (*Instance) GetSessions ¶
func (*Instance) Remove ¶
Remove a session from the account (DOES NOT DISCONNECT, there is an extra method for that)
func (*Instance) ReportClientError ¶
func (*Instance) ReportGeneralError ¶
func (*Instance) SendEventToOne ¶
Sends an event to the only ONE session of the connected account
func (*Instance) SendMessage ¶
func (*Instance) SendSession ¶
func (*Instance) SetupConnectionsCache ¶
func (*Instance) UpdateClient ¶
Click to show internal directories.
Click to hide internal directories.