-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_user.go
46 lines (38 loc) · 1.03 KB
/
api_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package tapd
import (
"context"
"net/http"
)
type UserRole struct {
ID string `json:"id"`
Name string `json:"name"`
}
// UserService is a service to interact with user related API
type UserService struct {
client *Client
}
// GetRolesRequest represents a request to get roles
type GetRolesRequest struct {
WorkspaceID *int `url:"workspace_id,omitempty"` // 项目 ID
}
// GetRoles 获取角色ID对照关系
//
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/user/get_roles.html
func (s *UserService) GetRoles(
ctx context.Context, request *GetRolesRequest, opts ...RequestOption,
) ([]*UserRole, *Response, error) {
req, err := s.client.NewRequest(ctx, http.MethodGet, "roles", request, opts)
if err != nil {
return nil, nil, err
}
var items map[string]string
resp, err := s.client.Do(req, &items)
if err != nil {
return nil, resp, err
}
roles := make([]*UserRole, 0, len(items))
for id, name := range items {
roles = append(roles, &UserRole{ID: id, Name: name})
}
return roles, resp, nil
}