MCPcopy Index your code
hub / github.com/coder/coder / ReadFileLines

Method ReadFileLines

codersdk/workspacesdk/agentconn.go:964–990  ·  view source on GitHub ↗

ReadFileLines reads a file with line-based offset and limit, returning line-numbered content with safety limits.

(ctx context.Context, path string, offset, limit int64, limits ReadFileLinesLimits)

Source from the content-addressed store, hash-verified

962// ReadFileLines reads a file with line-based offset and limit, returning
963// line-numbered content with safety limits.
964func (c *agentConn) ReadFileLines(ctx context.Context, path string, offset, limit int64, limits ReadFileLinesLimits) (ReadFileLinesResponse, error) {
965 ctx, span := tracing.StartSpan(ctx)
966 defer span.End()
967
968 res, err := c.apiRequest(ctx, http.MethodGet, agentAPIPath("/api/v0/read-file-lines", neturl.Values{
969 "path": []string{path},
970 "offset": []string{strconv.FormatInt(offset, 10)},
971 "limit": []string{strconv.FormatInt(limit, 10)},
972 "max_file_size": []string{strconv.FormatInt(limits.MaxFileSize, 10)},
973 "max_line_bytes": []string{strconv.Itoa(limits.MaxLineBytes)},
974 "max_response_lines": []string{strconv.Itoa(limits.MaxResponseLines)},
975 "max_response_bytes": []string{strconv.Itoa(limits.MaxResponseBytes)},
976 }), nil)
977 if err != nil {
978 return ReadFileLinesResponse{}, xerrors.Errorf("do request: %w", err)
979 }
980 defer res.Body.Close()
981 if res.StatusCode != http.StatusOK {
982 return ReadFileLinesResponse{}, codersdk.ReadBodyAsError(res)
983 }
984
985 var resp ReadFileLinesResponse
986 if err := json.NewDecoder(res.Body).Decode(&resp); err != nil {
987 return ReadFileLinesResponse{}, xerrors.Errorf("decode response: %w", err)
988 }
989 return resp, nil
990}
991
992// ReadFile reads from a file from the workspace, returning a file reader and
993// the mime type.

Callers

nothing calls this directly

Calls 6

apiRequestMethod · 0.95
StartSpanFunction · 0.92
ReadBodyAsErrorFunction · 0.92
agentAPIPathFunction · 0.85
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected