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

Function ParsePagination

coderd/pagination.go:14–34  ·  view source on GitHub ↗

ParsePagination extracts pagination query params from the http request. If an error is encountered, the error is written to w and ok is set to false.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

12// ParsePagination extracts pagination query params from the http request.
13// If an error is encountered, the error is written to w and ok is set to false.
14func ParsePagination(w http.ResponseWriter, r *http.Request) (p codersdk.Pagination, ok bool) {
15 ctx := r.Context()
16 queryParams := r.URL.Query()
17 parser := httpapi.NewQueryParamParser()
18 params := codersdk.Pagination{
19 AfterID: parser.UUID(queryParams, uuid.Nil, "after_id"),
20 // A limit of 0 should be interpreted by the SQL query as "null" or
21 // "no limit". Do not make this value anything besides 0.
22 Limit: int(parser.PositiveInt32(queryParams, 0, "limit")),
23 Offset: int(parser.PositiveInt32(queryParams, 0, "offset")),
24 }
25 if len(parser.Errors) > 0 {
26 httpapi.Write(ctx, w, http.StatusBadRequest, codersdk.Response{
27 Message: "Query parameters have invalid values.",
28 Validations: parser.Errors,
29 })
30 return params, false
31 }
32
33 return params, true
34}

Callers 12

TestPaginationFunction · 0.92
aiBridgeListSessionsMethod · 0.92
aiBridgeListModelsMethod · 0.92
aiBridgeListClientsMethod · 0.92
GetUsersMethod · 0.85
workspacesMethod · 0.85
auditLogsMethod · 0.85
listChatsMethod · 0.85
paginatedMembersMethod · 0.85
workspaceBuildsMethod · 0.85

Calls 5

UUIDMethod · 0.95
PositiveInt32Method · 0.95
NewQueryParamParserFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65

Tested by 1

TestPaginationFunction · 0.74