-
Notifications
You must be signed in to change notification settings - Fork 2
/
user.go
41 lines (33 loc) · 937 Bytes
/
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
package dockerhub
import (
"context"
"net/http"
"time"
)
type UserService service
type User struct {
ID string `json:"id"`
Username string `json:"username"`
FullName string `json:"full_name"`
Location string `json:"location"`
Company string `json:"company"`
GravatarEmail string `json:"gravatar_email"`
IsStaff bool `json:"is_staff"`
IsAdmin bool `json:"is_admin"`
ProfileURL string `json:"profile_url"`
DateJoined time.Time `json:"date_joined"`
GravatarURL string `json:"gravatar_url"`
Type string `json:"type"`
}
func (s *UserService) GetLoggedInUser(ctx context.Context) (*User, error) {
url := "/user/"
req, err := s.client.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
res := &User{}
if _, err := s.client.Do(ctx, req, res); err != nil {
return nil, err
}
return res, nil
}