mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-23 02:51:37 +01:00
ab4e11ae4d
Update "code.gitea.io/sdk/gitea" to latest release Reviewed-on: https://gitea.com/gitea/tea/pulls/385 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
// 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()
|
|
}
|
|
|
|
func (c *Client) searchUsers(rawQuery string) ([]*User, *Response, error) {
|
|
link, _ := url.Parse("/users/search")
|
|
link.RawQuery = rawQuery
|
|
userResp := new(searchUsersResponse)
|
|
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &userResp)
|
|
return userResp.Users, resp, err
|
|
}
|
|
|
|
// SearchUsers finds users by query
|
|
func (c *Client) SearchUsers(opt SearchUsersOption) ([]*User, *Response, error) {
|
|
return c.searchUsers(opt.QueryEncode())
|
|
}
|