Skip to content

Commit ecbea09

Browse files
committed
add test case
1 parent 48424fe commit ecbea09

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

event.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sseread
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"strings"
67
)
@@ -23,6 +24,7 @@ type Event struct {
2324
// ParseEventLine is a method of the Event struct that parses an event field based on the event type.
2425
// It takes an event type and event data as input, and updates the corresponding field in the Event struct.
2526
func (e *Event) ParseEventLine(lineType string, lineData []byte) {
27+
2628
switch strings.TrimSpace(lineType) {
2729
case "event":
2830
e.Event = string(lineData) // If the event type is "event", update the Event field.
@@ -31,6 +33,11 @@ func (e *Event) ParseEventLine(lineType string, lineData []byte) {
3133
case "retry":
3234
e.ID = string(lineData) // If the event type is "retry", update the Retry field.
3335
case "data":
34-
e.Data = lineData // If the event type is "data", update the Data field.
36+
if bytes.EqualFold(lineData, []byte("[DONE]")) {
37+
e.Data = nil
38+
} else {
39+
e.Data = lineData // If the event type is "data", update the Data field.
40+
}
3541
}
42+
3643
}

0 commit comments

Comments
 (0)