Пример #1
0
func (c *WebSocketConn) Read() (sarif.Message, error) {
	var msg sarif.Message
	_, r, err := c.conn.NextReader()
	if err != nil {
		return msg, err
	}
	if err := json.NewDecoder(r).Decode(&msg); err != nil {
		return msg, err
	}
	return msg, msg.IsValid()
}
Пример #2
0
func (c *WebSocketConn) Write(msg sarif.Message) error {
	if err := msg.IsValid(); err != nil {
		return err
	}
	w, err := c.conn.NextWriter(websocket.TextMessage)
	if err != nil {
		return err
	}
	defer w.Close()
	return json.NewEncoder(w).Encode(msg)
}