-
Notifications
You must be signed in to change notification settings - Fork 82
/
account_logins.go
58 lines (45 loc) · 1.17 KB
/
account_logins.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
58
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
type Login struct {
ID int `json:"id"`
Datetime *time.Time `json:"datetime"`
IP string `json:"ip"`
Restricted bool `json:"restricted"`
Username string `json:"username"`
Status string `json:"status"`
}
func (c *Client) ListLogins(ctx context.Context, opts *ListOptions) ([]Login, error) {
response, err := getPaginatedResults[Login](ctx, c, "account/logins", opts)
if err != nil {
return nil, err
}
return response, nil
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (i *Login) UnmarshalJSON(b []byte) error {
type Mask Login
l := struct {
*Mask
Datetime *parseabletime.ParseableTime `json:"datetime"`
}{
Mask: (*Mask)(i),
}
if err := json.Unmarshal(b, &l); err != nil {
return err
}
i.Datetime = (*time.Time)(l.Datetime)
return nil
}
func (c *Client) GetLogin(ctx context.Context, loginID int) (*Login, error) {
e := formatAPIPath("account/logins/%d", loginID)
response, err := doGETRequest[Login](ctx, c, e)
if err != nil {
return nil, err
}
return response, nil
}