Documentation ¶
Index ¶
- Constants
- type Client
- type EventHandler
- type Huginn
- func (h *Huginn) AddClient(conn *websocket.Conn) string
- func (h *Huginn) Emit(message Message, mode int, clients []string)
- func (h *Huginn) On(event string, handler EventHandler)
- func (h *Huginn) RemoveClient(clientID string)
- func (h *Huginn) RemoveMetadata(clientID, key string)
- func (h *Huginn) SearchClient(key string, value interface{}) (*Client, error)
- func (h *Huginn) Server(w http.ResponseWriter, r *http.Request)
- func (h *Huginn) Shutdown()
- func (h *Huginn) UpdateMetadata(clientID, key string, val interface{})
- type Message
- type Metadata
Constants ¶
const ( EmitAll = iota EmitOnly EmitExcept )
Emit sends a message to clients based on the selected mode.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventHandler ¶
EventHandler defines the function signature for event handling.
type Huginn ¶
type Huginn struct { Clients sync.Map // Use sync.Map instead of manual mutex locking Events map[string]EventHandler Upgrader *websocket.Upgrader DB *mongo.Collection // Optional MongoDB collection }
Huginn manages WebSocket clients, events, and optional persistence.
func (*Huginn) AddClient ¶
AddClient adds a new WebSocket client and stores it with optional persistence.
func (*Huginn) On ¶
func (h *Huginn) On(event string, handler EventHandler)
On registers a handler for a specific event.
func (*Huginn) RemoveClient ¶
RemoveClient removes a client and deletes its data if MongoDB is enabled.
func (*Huginn) RemoveMetadata ¶
RemoveMetadata removes a key from the client's metadata.
func (*Huginn) SearchClient ¶
SearchClient searches for a client by a specific key and value in the metadata.
func (*Huginn) Server ¶
func (h *Huginn) Server(w http.ResponseWriter, r *http.Request)
Server handles incoming WebSocket connections.
func (*Huginn) Shutdown ¶
func (h *Huginn) Shutdown()
Shutdown gracefully closes all client connections and cleans up resources.
func (*Huginn) UpdateMetadata ¶
UpdateMetadata adds or updates a key-value pair in a client's metadata.