Documentation
¶
Index ¶
- Variables
- func CreateHandlerFor[T, A any](instance *Instance[T], action string, handler func(*Context[T], A) Event)
- func DefaultDecodingMiddleware[T any](session *Session[T], instance *Instance[T], bytes []byte) ([]byte, error)
- func DefaultEncodingMiddleware[T any](session *Session[T], instance *Instance[T], message []byte) ([]byte, error)
- func GenerateToken(tkLength int32) string
- type Adapter
- type AdapterContext
- type AdapterFunc
- type AdapterSendError
- type Config
- type Context
- type CreateAction
- type Event
- type Instance
- func (instance *Instance[T]) Adapt(createAction CreateAction)
- func (instance *Instance[T]) AdapterReceive(ID string, event Event, msg []byte) error
- func (instance *Instance[T]) DisconnectSession(userId string, sessionId string)
- func (instance *Instance[T]) ExistsConnection(userId string, sessionId string) bool
- func (instance *Instance[T]) Get(userId string, sessionId string) (*Session[T], bool)
- func (instance *Instance[T]) GetConnections(userId string) int
- func (instance *Instance[T]) GetSessions(userId string) []string
- func (instance *Instance[T]) Handle(ctx *Context[T]) bool
- func (instance *Instance[T]) MountGateway(router fiber.Router)
- func (instance *Instance[T]) RemoveAdapter(ID string)
- func (instance *Instance[T]) RemoveSession(userId string, sessionId string)
- func (instance *Instance[T]) ReportGeneralError(context string, err error)
- func (instance *Instance[T]) ReportSessionError(session *Session[T], context string, err error)
- func (instance *Instance[T]) Send(adapters []string, event Event) error
- func (instance *Instance[T]) SendEventToSession(c *Session[T], event Event) error
- func (instance *Instance[T]) SendEventToUser(userId string, event Event) error
- func (instance *Instance[T]) SendOne(adapter string, event Event) error
- type Message
- type None
- type NormalResponseStruct
- type Session
- type SessionCache
- type SessionInfo
- type SessionsList
Constants ¶
This section is empty.
Variables ¶
var DebugLogs = true
Functions ¶
func CreateHandlerFor ¶
func CreateHandlerFor[T, A any](instance *Instance[T], action string, handler func(*Context[T], A) Event)
Create a handler for an action using generics (with parsing already implemented)
func DefaultDecodingMiddleware ¶
func DefaultDecodingMiddleware[T any](session *Session[T], instance *Instance[T], bytes []byte) ([]byte, error)
Default pipes-fiber decoding middleware (using JSON)
func DefaultEncodingMiddleware ¶
func DefaultEncodingMiddleware[T any](session *Session[T], instance *Instance[T], message []byte) ([]byte, error)
Default pipes-fiber encoding middleware (using JSON)
func GenerateToken ¶
Types ¶
type Adapter ¶
type Adapter struct {
ID string // Identifier of the adapter
Mutex *sync.Mutex // Mutex to prevent concurrent exceptions (can happen with connections, better handle this on the neogate level)
// Functions
OnEvent AdapterFunc
OnError func(error)
}
type AdapterContext ¶
type AdapterFunc ¶
type AdapterFunc = func(*AdapterContext) error
type AdapterSendError ¶
func (*AdapterSendError) Error ¶
func (err *AdapterSendError) Error() string
type Config ¶
type Config[T any] struct { // Called when a client attempts to connect(create a session). Return the session info and true if the connection is allowed. // MUST BE SPECIFIED. Handshake func(c *fiber.Ctx) (SessionInfo[T], bool) // Session handlers SessionDisconnectHandler func(session *Session[T]) SessionEnterNetworkHandler func(session *Session[T], data T) bool // Called after pipes adapter is registered, returns if the client should be disconnected (true = disconnect) // Determines the id of the event adapter for a session. // Returns id of user adapter based on session.GetUserId(), and if of session adapter based on session.GetSessionId() SessionAdapterHandler func(userId string, sessionId string) (string, string) // Codec middleware EncodingMiddleware func(session *Session[T], instance *Instance[T], message []byte) ([]byte, error) DecodingMiddleware func(session *Session[T], instance *Instance[T], message []byte) ([]byte, error) // Error handler ErrorHandler func(err error) }
! If the functions aren't implemented pipesfiber will panic The generic should be the type of the handshake request
type CreateAction ¶
type CreateAction struct {
ID string // Id of the adapter
OnEvent AdapterFunc // Function that handles events received by the adapter
OnError func(error) // Function that handles errors encountered by the adapter
}
type Event ¶
func SuccessResponse ¶
type Instance ¶
func Setup ¶
Setup neogate using the config. Use the returned *Instance for interfacing with neogate.
func (*Instance[T]) Adapt ¶
func (instance *Instance[T]) Adapt(createAction CreateAction)
Register a new adapter for websocket/sl (all safe protocols)
func (*Instance[T]) AdapterReceive ¶
Handles receiving messages from the target and passes them to the adapter
func (*Instance[T]) DisconnectSession ¶
DisconnectSession closes/disconnects the session
func (*Instance[T]) ExistsConnection ¶
func (*Instance[T]) GetConnections ¶
func (*Instance[T]) GetSessions ¶
func (*Instance[T]) MountGateway ¶
Mount the neogate gateway using a fiber router.
func (*Instance[T]) RemoveAdapter ¶
Remove an adapter from the instance
func (*Instance[T]) RemoveSession ¶
RemoveSession a session from the users sessions (DOES NOT DISCONNECT, there is an extra method for that)
func (*Instance[T]) ReportGeneralError ¶
func (*Instance[T]) ReportSessionError ¶
func (*Instance[T]) SendEventToSession ¶
Sends an event to a specific Session
func (*Instance[T]) SendEventToUser ¶
SendEventToUser sends the event to all sessions connected to the userId
type NormalResponseStruct ¶
type Session ¶
type Session[T any] struct { // contains filtered or unexported fields }
func (*Session[T]) GetSessionId ¶
type SessionCache ¶
type SessionCache struct {
// contains filtered or unexported fields
}
type SessionInfo ¶
type SessionInfo[T any] struct { UserId string // Identifier of the user Data T // Session data you can decide how to fill // contains filtered or unexported fields }
Used to provide information for session creation
type SessionsList ¶
type SessionsList struct {
// contains filtered or unexported fields
}
func (*SessionsList) Add ¶
func (sessionList *SessionsList) Add(sessionId string)