-
Notifications
You must be signed in to change notification settings - Fork 11
/
account.go
40 lines (33 loc) · 906 Bytes
/
account.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
package replicate
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
type Account struct {
Type string `json:"type"`
Username string `json:"username"`
Name string `json:"name"`
GithubURL string `json:"github_url"`
rawJSON json.RawMessage `json:"-"`
}
func (a *Account) RawJSON() json.RawMessage {
return a.rawJSON
}
var _ json.Unmarshaler = (*Account)(nil)
func (a *Account) UnmarshalJSON(data []byte) error {
a.rawJSON = data
type Alias Account
alias := &struct{ *Alias }{Alias: (*Alias)(a)}
return json.Unmarshal(data, alias)
}
// GetCurrentAccount returns the authenticated user or organization.
func (r *Client) GetCurrentAccount(ctx context.Context) (*Account, error) {
response := &Account{}
err := r.fetch(ctx, http.MethodGet, "/account", nil, response)
if err != nil {
return nil, fmt.Errorf("failed to list collections: %w", err)
}
return response, nil
}