summaryrefslogtreecommitdiffstats
path: root/vendor/code.gitea.io/sdk/gitea/user_search.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/code.gitea.io/sdk/gitea/user_search.go')
-rw-r--r--vendor/code.gitea.io/sdk/gitea/user_search.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/code.gitea.io/sdk/gitea/user_search.go b/vendor/code.gitea.io/sdk/gitea/user_search.go
new file mode 100644
index 0000000000..7e4064d18e
--- /dev/null
+++ b/vendor/code.gitea.io/sdk/gitea/user_search.go
@@ -0,0 +1,44 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package gitea
+
+import (
+ "fmt"
+ "net/url"
+)
+
+type searchUsersResponse struct {
+ Users []*User `json:"data"`
+}
+
+// SearchUsersOption options for SearchUsers
+type SearchUsersOption struct {
+ ListOptions
+ KeyWord string
+}
+
+// QueryEncode turns options into querystring argument
+func (opt *SearchUsersOption) QueryEncode() string {
+ query := make(url.Values)
+ if opt.Page > 0 {
+ query.Add("page", fmt.Sprintf("%d", opt.Page))
+ }
+ if opt.PageSize > 0 {
+ query.Add("limit", fmt.Sprintf("%d", opt.PageSize))
+ }
+ if len(opt.KeyWord) > 0 {
+ query.Add("q", opt.KeyWord)
+ }
+ return query.Encode()
+}
+
+// SearchUsers finds users by query
+func (c *Client) SearchUsers(opt SearchUsersOption) ([]*User, *Response, error) {
+ link, _ := url.Parse("/users/search")
+ link.RawQuery = opt.QueryEncode()
+ userResp := new(searchUsersResponse)
+ resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &userResp)
+ return userResp.Users, resp, err
+}