event.go
func NewEventStreamReader(eventStream io.Reader) *EventStreamReader {
	scanner := bufio.NewScanner(eventStream)
	split := func(data []byte, atEOF bool) (int, []byte, error) {
		if atEOF && len(data) == 0 {
			return 0, nil, nil
		}

		// We have a full event payload to parse.
		if i := bytes.Index(data, []byte("\r\n\r\n")); i >= 0 {
			return i + 1, data[0:i], nil
		}
		if i := bytes.Index(data, []byte("\r\r")); i >= 0 {
			return i + 1, data[0:i], nil
		}
		if i := bytes.Index(data, []byte("\n\n")); i >= 0 {
			return i + 1, data[0:i], nil
		}
		// If we're at EOF, we have all of the data.
		if atEOF {
			return len(data), data, nil
		}
		// Request more data.
		return 0, nil, nil
	}
	// Set the split function for the scanning operation.
	scanner.Split(split)

	return &EventStreamReader{
		scanner: scanner,
	}
}
func NewEventStreamReader(eventStream io.Reader) *EventStreamReader {
	scanner := bufio.NewScanner(eventStream)
	split := func(data []byte, atEOF bool) (int, []byte, error) {
		if atEOF && len(data) == 0 {
			return 0, nil, nil
		}

		// We have a full event payload to parse.
		if i := bytes.Index(data, []byte("\r\n\r\n")); i >= 0 {
			return i + 1, data[0:i], nil
		}
		if i := bytes.Index(data, []byte("\r\r")); i >= 0 {
			return i + 1, data[0:i], nil
		}
		if i := bytes.Index(data, []byte("\n\n")); i >= 0 {
			return i + 1, data[0:i], nil
		}
		// If we're at EOF, we have all of the data.
		if atEOF {
			return len(data), data, nil
		}
		// Request more data.
		return 0, nil, nil
	}
	// Set the split function for the scanning operation.
	scanner.Split(split)

	return &EventStreamReader{
		scanner: scanner,
	}
}
// NewEventStreamReader creates an instance of EventStreamReader.