-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentity.go
43 lines (35 loc) · 915 Bytes
/
identity.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
package discogs
import (
"context"
"fmt"
"encoding/json"
)
type IdentityService service
type Identity struct {
ID int `json:"id"`
Username string `json:"username"`
ResourceURL string `json:"resource_url"`
ConsumerName string `json:"consumer_name"`
}
func (s *IdentityService) Get() (id *Identity, err error) {
req, err := s.client.NewRequest("GET", "oauth/identity", nil)
if err != nil {
err = fmt.Errorf("error building auth check request: %w", err)
return
}
resp, err := s.client.Do(context.TODO(), req)
if err != nil {
err = fmt.Errorf("error sending auth check request: %w", err)
return
}
if resp.StatusCode != 200 {
err = fmt.Errorf("got non-200 from auth check endpoint: %d", resp.StatusCode)
return
}
err = json.NewDecoder(resp.Body).Decode(&id)
if err != nil {
err = fmt.Errorf("error decoding identity response body: %w", err)
return
}
return
}