--------------------------------------------------------------------------- Common helpers --------------------------------------------------------------------------- extractSSEJSON extracts the JSON payload from an SSE data line within a chunk.
(chunk []byte)
| 329 | |
| 330 | // extractSSEJSON extracts the JSON payload from an SSE data line within a chunk. |
| 331 | func extractSSEJSON(chunk []byte) []byte { |
| 332 | for _, line := range bytes.Split(chunk, []byte("\n")) { |
| 333 | line = bytes.TrimSpace(line) |
| 334 | if bytes.HasPrefix(line, []byte("data:")) { |
| 335 | data := bytes.TrimPrefix(line, []byte("data:")) |
| 336 | data = bytes.TrimSpace(data) |
| 337 | if len(data) > 0 && data[0] == '{' { |
| 338 | return data |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return nil |
| 343 | } |
| 344 | |
| 345 | // sseJSONReplace applies a transform function to the JSON payload inside an SSE |
| 346 | // data line, returning the chunk with the modified JSON. |
no outgoing calls