MCPcopy Create free account
hub / github.com/gogs/gogs / Search

Function Search

internal/route/api/v1/user/user.go:13–44  ·  view source on GitHub ↗
(c *context.APIContext)

Source from the content-addressed store, hash-verified

11)
12
13func Search(c *context.APIContext) {
14 pageSize := c.QueryInt("limit")
15 if pageSize <= 0 {
16 pageSize = 10
17 }
18 users, _, err := database.Handle.Users().SearchByName(c.Req.Context(), c.Query("q"), 1, pageSize, "")
19 if err != nil {
20 c.JSON(http.StatusInternalServerError, map[string]any{
21 "ok": false,
22 "error": err.Error(),
23 })
24 return
25 }
26
27 results := make([]*api.User, len(users))
28 for i := range users {
29 results[i] = &api.User{
30 ID: users[i].ID,
31 UserName: users[i].Name,
32 AvatarUrl: users[i].AvatarURL(),
33 FullName: markup.Sanitize(users[i].FullName),
34 }
35 if c.IsLogged {
36 results[i].Email = users[i].Email
37 }
38 }
39
40 c.JSONSuccess(map[string]any{
41 "ok": true,
42 "data": results,
43 })
44}
45
46func GetInfo(c *context.APIContext) {
47 u, err := database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(":username"))

Callers

nothing calls this directly

Calls 6

SanitizeFunction · 0.92
UsersMethod · 0.80
AvatarURLMethod · 0.80
JSONSuccessMethod · 0.80
SearchByNameMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected