Documentation ¶
Overview ¶
Package websocket contains helpers and implementation for backend functions that interact with the frontend over websockets.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
Conn is a wrapper for a standard websocket connection with utility methods added for interacting with Kolide specific message types.
func (*Conn) ReadAuthToken ¶
ReadAuthToken reads from the websocket, returning an auth token embedded in a JSONMessage with type "auth" and data that can be unmarshalled to authData.
func (*Conn) ReadJSONMessage ¶
func (c *Conn) ReadJSONMessage() (*JSONMessage, error)
ReadJSONMessage reads an incoming Message from JSON. Note that the Message.Data field is guaranteed to be *json.RawMessage, and so unchecked type assertions may be performed as in:
msg, err := c.ReadJSONMessage() if err == nil && msg.Type == "foo" { var foo fooData json.Unmarshal(*(msg.Data.(*json.RawMessage)), &foo) }
func (*Conn) WriteJSON ¶
func (c *Conn) WriteJSON(msg JSONMessage) error
func (*Conn) WriteJSONError ¶
WriteJSONError writes an error (Message struct with Type="error"), returning any error condition from the connection.
func (*Conn) WriteJSONMessage ¶
WriteJSONMessage writes the provided data as JSON (using the Message struct), returning any error condition from the connection.
type JSONMessage ¶
type JSONMessage struct { // Type is a string indicating which message type the data contains Type string `json:"type"` // Data contains the arbitrarily schemaed JSON data. Type should // indicate how this should be deserialized. Data interface{} `json:"data"` }
JSONMessage is a wrapper struct for messages that will be sent across the wire as JSON.