IntoServerEvent unmarshals the provided ServerEvent into the proper type.
(e *ServerEvent, eventType ServerEventType)
| 221 | |
| 222 | // IntoServerEvent unmarshals the provided ServerEvent into the proper type. |
| 223 | func IntoServerEvent[T EventLog](e *ServerEvent, eventType ServerEventType) (*T, bool) { |
| 224 | if e.Type != eventType { |
| 225 | return nil, false |
| 226 | } |
| 227 | event := new(T) |
| 228 | err := json.Unmarshal(e.event, event) |
| 229 | if err != nil { |
| 230 | return nil, false |
| 231 | } |
| 232 | return event, true |
| 233 | } |
| 234 | |
| 235 | // ReadEvent will read a message from the websocket connection and parse it into a valid ServerEvent. |
| 236 | func ReadServerEvent(c *websocket.Conn, ctx context.Context) (*ServerEvent, error) { |