FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
github-mcp-server/pkg/buffer/buffer.go at main · erifystudio/github-mcp-server · GitHub
erifystudio
/
github-mcp-server
Public
forked from
github/github-mcp-server
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
github-mcp-server
/
pkg
/
buffer
/
buffer.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (59 loc) · 1.96 KB
Breadcrumbs
github-mcp-server
/
pkg
/
buffer
/
buffer.go
Copy path
File metadata and controls
69 lines (59 loc) · 1.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package
buffer
import
(
"bufio"
"fmt"
"net/http"
"strings"
)
// ProcessResponseAsRingBufferToEnd reads the body of an HTTP response line by line,
// storing only the last maxJobLogLines lines using a ring buffer (sliding window).
// This efficiently retains the most recent lines, overwriting older ones as needed.
//
// Parameters:
//
// httpResp: The HTTP response whose body will be read.
// maxJobLogLines: The maximum number of log lines to retain.
//
// Returns:
//
// string: The concatenated log lines (up to maxJobLogLines), separated by newlines.
// int: The total number of lines read from the response.
// *http.Response: The original HTTP response.
// error: Any error encountered during reading.
//
// The function uses a ring buffer to efficiently store only the last maxJobLogLines lines.
// If the response contains more lines than maxJobLogLines, only the most recent lines are kept.
func
ProcessResponseAsRingBufferToEnd
(
httpResp
*
http.
Response
,
maxJobLogLines
int
) (
string
,
int
,
*
http.
Response
,
error
) {
lines
:=
make
([]
string
,
maxJobLogLines
)
validLines
:=
make
([]
bool
,
maxJobLogLines
)
totalLines
:=
0
writeIndex
:=
0
scanner
:=
bufio
.
NewScanner
(
httpResp
.
Body
)
scanner
.
Buffer
(
make
([]
byte
,
0
,
64
*
1024
),
1024
*
1024
)
for
scanner
.
Scan
() {
line
:=
scanner
.
Text
()
totalLines
++
lines
[
writeIndex
]
=
line
validLines
[
writeIndex
]
=
true
writeIndex
=
(
writeIndex
+
1
)
%
maxJobLogLines
}
if
err
:=
scanner
.
Err
();
err
!=
nil
{
return
""
,
0
,
httpResp
,
fmt
.
Errorf
(
"failed to read log content: %w"
,
err
)
}
var
result
[]
string
linesInBuffer
:=
totalLines
if
linesInBuffer
>
maxJobLogLines
{
linesInBuffer
=
maxJobLogLines
}
startIndex
:=
0
if
totalLines
>
maxJobLogLines
{
startIndex
=
writeIndex
}
for
i
:=
0
;
i
<
linesInBuffer
;
i
++
{
idx
:=
(
startIndex
+
i
)
%
maxJobLogLines
if
validLines
[
idx
] {
result
=
append
(
result
,
lines
[
idx
])
}
}
return
strings
.
Join
(
result
,
"
\n
"
),
totalLines
,
httpResp
,
nil
}
Back
|
FazBrowse Home
|
New Git URL