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

Method HandleReadFileLines

agent/agentfiles/files.go:142–170  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

140}
141
142func (api *API) HandleReadFileLines(rw http.ResponseWriter, r *http.Request) {
143 ctx := r.Context()
144
145 query := r.URL.Query()
146 parser := httpapi.NewQueryParamParser().RequiredNotEmpty("path")
147 path := parser.String(query, "", "path")
148 offset := parser.PositiveInt64(query, 1, "offset")
149 limit := parser.PositiveInt64(query, 0, "limit")
150 maxFileSize := parser.PositiveInt64(query, workspacesdk.DefaultMaxFileSize, "max_file_size")
151 maxLineBytes := parser.PositiveInt64(query, workspacesdk.DefaultMaxLineBytes, "max_line_bytes")
152 maxResponseLines := parser.PositiveInt64(query, workspacesdk.DefaultMaxResponseLines, "max_response_lines")
153 maxResponseBytes := parser.PositiveInt64(query, workspacesdk.DefaultMaxResponseBytes, "max_response_bytes")
154 parser.ErrorExcessParams(query)
155 if len(parser.Errors) > 0 {
156 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
157 Message: "Query parameters have invalid values.",
158 Validations: parser.Errors,
159 })
160 return
161 }
162
163 resp := api.readFileLines(ctx, path, offset, limit, workspacesdk.ReadFileLinesLimits{
164 MaxFileSize: maxFileSize,
165 MaxLineBytes: int(maxLineBytes),
166 MaxResponseLines: int(maxResponseLines),
167 MaxResponseBytes: int(maxResponseBytes),
168 })
169 httpapi.Write(ctx, rw, http.StatusOK, resp)
170}
171
172func (api *API) readFileLines(_ context.Context, path string, offset, limit int64, limits workspacesdk.ReadFileLinesLimits) ReadFileLinesResponse {
173 errResp := func(msg string) ReadFileLinesResponse {

Callers

nothing calls this directly

Calls 8

readFileLinesMethod · 0.95
NewQueryParamParserFunction · 0.92
WriteFunction · 0.92
RequiredNotEmptyMethod · 0.80
PositiveInt64Method · 0.80
ErrorExcessParamsMethod · 0.80
ContextMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected