Skip to content

Commit ec070ee

Browse files
Update pkg/buffer/buffer.go
Co-authored-by: Copilot <[email protected]>
1 parent d9c8825 commit ec070ee

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/buffer/buffer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ import (
77
"strings"
88
)
99

10+
// ProcessResponseAsRingBufferToEnd reads the body of an HTTP response line by line,
11+
// storing only the last maxJobLogLines lines using a ring buffer (sliding window).
12+
// This efficiently retains the most recent lines, overwriting older ones as needed.
13+
//
14+
// Parameters:
15+
// httpResp: The HTTP response whose body will be read.
16+
// maxJobLogLines: The maximum number of log lines to retain.
17+
//
18+
// Returns:
19+
// string: The concatenated log lines (up to maxJobLogLines), separated by newlines.
20+
// int: The total number of lines read from the response.
21+
// *http.Response: The original HTTP response.
22+
// error: Any error encountered during reading.
23+
//
24+
// The function uses a ring buffer to efficiently store only the last maxJobLogLines lines.
25+
// If the response contains more lines than maxJobLogLines, only the most recent lines are kept.
1026
func ProcessResponseAsRingBufferToEnd(httpResp *http.Response, maxJobLogLines int) (string, int, *http.Response, error) {
1127
lines := make([]string, maxJobLogLines)
1228
validLines := make([]bool, maxJobLogLines)

0 commit comments

Comments
 (0)