Skip to content

Commit a424a08

Browse files
Add last_login support in User struct (#583)
1 parent 108afdf commit a424a08

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

account_users.go

+27
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@ const (
1717
UserTypeDefault UserType = "default"
1818
)
1919

20+
// LastLogin represents a LastLogin object
21+
type LastLogin struct {
22+
LoginDatetime *time.Time `json:"-"`
23+
Status string `json:"status"`
24+
}
25+
2026
// User represents a User object
2127
type User struct {
2228
Username string `json:"username"`
2329
Email string `json:"email"`
30+
LastLogin *LastLogin `json:"last_login"`
2431
UserType UserType `json:"user_type"`
2532
Restricted bool `json:"restricted"`
2633
TFAEnabled bool `json:"tfa_enabled"`
@@ -42,6 +49,26 @@ type UserUpdateOptions struct {
4249
Restricted *bool `json:"restricted,omitempty"`
4350
}
4451

52+
// UnmarshalJSON implements the json.Unmarshaler interface
53+
func (ll *LastLogin) UnmarshalJSON(b []byte) error {
54+
type Mask LastLogin
55+
56+
p := struct {
57+
*Mask
58+
LoginDatetime *parseabletime.ParseableTime `json:"login_datetime"`
59+
}{
60+
Mask: (*Mask)(ll),
61+
}
62+
63+
if err := json.Unmarshal(b, &p); err != nil {
64+
return err
65+
}
66+
67+
ll.LoginDatetime = (*time.Time)(p.LoginDatetime)
68+
69+
return nil
70+
}
71+
4572
// UnmarshalJSON implements the json.Unmarshaler interface
4673
func (i *User) UnmarshalJSON(b []byte) error {
4774
type Mask User

0 commit comments

Comments
 (0)