Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
xJack21 committed Mar 17, 2024
1 parent 48424fe commit ecbea09
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion event.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sseread

import (
"bytes"
"encoding/json"
"strings"
)
Expand All @@ -23,6 +24,7 @@ type Event struct {
// ParseEventLine is a method of the Event struct that parses an event field based on the event type.
// It takes an event type and event data as input, and updates the corresponding field in the Event struct.
func (e *Event) ParseEventLine(lineType string, lineData []byte) {

switch strings.TrimSpace(lineType) {
case "event":
e.Event = string(lineData) // If the event type is "event", update the Event field.
Expand All @@ -31,6 +33,11 @@ func (e *Event) ParseEventLine(lineType string, lineData []byte) {
case "retry":
e.ID = string(lineData) // If the event type is "retry", update the Retry field.
case "data":
e.Data = lineData // If the event type is "data", update the Data field.
if bytes.EqualFold(lineData, []byte("[DONE]")) {
e.Data = nil
} else {
e.Data = lineData // If the event type is "data", update the Data field.
}
}

}

0 comments on commit ecbea09

Please sign in to comment.