forked from 0xch4z/dockerhub-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
44 lines (36 loc) · 1.02 KB
/
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
package dockerhub
import (
"context"
"net/http"
"time"
)
//UserService type
type UserService service
// User response json data
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"`
}
// GetLoggedInUser get the current user logged in to docker hub
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
}