-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
45 lines (37 loc) · 959 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
package meroxa
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
const usersPath = "/v1/users"
type User struct {
UUID string `json:"uuid"`
Username string `json:"username,omitempty"`
Email string `json:"email,omitempty"`
GivenName string `json:"given_name,omitempty"`
FamilyName string `json:"family_name,omitempty"`
Verified bool `json:"email_verified,omitempty"`
LastLogin time.Time `json:"last_login,omitempty"`
Features []string `json:"features,omitempty"`
}
// GetUser returns a User with
func (c *client) GetUser(ctx context.Context) (*User, error) {
path := fmt.Sprintf("%s/me", usersPath)
resp, err := c.MakeRequest(ctx, http.MethodGet, path, nil, nil, nil)
if err != nil {
return nil, err
}
err = handleAPIErrors(resp)
if err != nil {
return nil, err
}
var u User
err = json.NewDecoder(resp.Body).Decode(&u)
if err != nil {
return nil, err
}
return &u, nil
}