Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created September 10, 2022 06:13
Show Gist options
  • Save percybolmer/8242ccab9fc5dc2da7942faca3b37964 to your computer and use it in GitHub Desktop.
Save percybolmer/8242ccab9fc5dc2da7942faca3b37964 to your computer and use it in GitHub Desktop.
package main
import "encoding/json"
// Event is the Messages sent over the websocket
// Used to differ between different actions
type Event struct {
// Type is the message type sent
Type string `json:"type"`
// Payload is the data Based on the Type
Payload json.RawMessage `json:"payload"`
}
// EventHandler is a function signature that is used to affect messages on the socket and triggered
// depending on the type
type EventHandler func(event Event, c *Client) error
const (
// EventSendMessage is the event name for new chat messages sent
EventSendMessage = "send_message"
)
// SendMessageEvent is the payload sent in the
// send_message event
type SendMessageEvent struct {
Message string `json:"message"`
From string `json:"from"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment