-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
57 lines (49 loc) · 885 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package sn
import (
"encoding/json"
"fmt"
)
type User struct {
Id int `json:"id,string"`
Name string `json:"name"`
Privates UserPrivates `json:"privates"`
}
type UserPrivates struct {
Sats int `json:"sats"`
}
type MeResponse struct {
Errors []GqlError `json:"errors"`
Data struct {
Me User `json:"me"`
} `json:"data"`
}
func (c *Client) Me() (*User, error) {
body := GqlBody{
Query: `
query me {
me {
id
name
privates {
sats
}
}
}`,
}
resp, err := c.callApi(body)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var respBody MeResponse
err = json.NewDecoder(resp.Body).Decode(&respBody)
if err != nil {
err = fmt.Errorf("error decoding me: %w", err)
return nil, err
}
err = c.checkForErrors(respBody.Errors)
if err != nil {
return nil, err
}
return &respBody.Data.Me, nil
}