예제 #1
0
func parseEvent(data []byte) (result sse.Event, err error) {
	r := bytes.NewReader(data)
	events, err := sse.Decode(r)
	if err != nil {
		return
	}

	if len(events) != 1 {
		err = fmt.Errorf("only expected 1 event, got: %d", len(events))
		return
	}

	result = events[0]
	return
}
예제 #2
0
파일: conn.go 프로젝트: manucorporat/tonic
func (c *conn) nextpackage() error {
	msgType, reader, err := c.socket.NextReader()
	if err != nil {
		return err
	}
	if msgType != websocket.TextMessage {
		return nil
	}
	events, err := sse.Decode(reader)
	if err != nil {
		return err
	}
	for _, event := range events {
		c.pending.Enqueue(common.NewMsg(
			event.Event,
			event.Id,
			"",
			event.Data))
	}
	return nil
}