-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.go
51 lines (36 loc) · 858 Bytes
/
users.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
47
48
49
50
51
package matata
import (
"context"
"fmt"
"net/http"
)
type User struct {
ID int `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Status string `json:"status"`
Groups []string `json:"groups"`
}
type UserList []User
func (c *Client) GetUsers(ctx context.Context) (*UserList, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/users", c.BaseURL), nil)
if err != nil {
return nil, err
}
res := UserList{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}
func (c *Client) GetCurrentUser(ctx context.Context) (*User, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/users/me", c.BaseURL), nil)
if err != nil {
return nil, err
}
res := User{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}