Skip to content

Commit

Permalink
Add last_login support in User struct (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai committed Sep 19, 2024
1 parent 108afdf commit a424a08
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions account_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ const (
UserTypeDefault UserType = "default"
)

// LastLogin represents a LastLogin object
type LastLogin struct {
LoginDatetime *time.Time `json:"-"`
Status string `json:"status"`
}

// User represents a User object
type User struct {
Username string `json:"username"`
Email string `json:"email"`
LastLogin *LastLogin `json:"last_login"`
UserType UserType `json:"user_type"`
Restricted bool `json:"restricted"`
TFAEnabled bool `json:"tfa_enabled"`
Expand All @@ -42,6 +49,26 @@ type UserUpdateOptions struct {
Restricted *bool `json:"restricted,omitempty"`
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (ll *LastLogin) UnmarshalJSON(b []byte) error {
type Mask LastLogin

p := struct {
*Mask
LoginDatetime *parseabletime.ParseableTime `json:"login_datetime"`
}{
Mask: (*Mask)(ll),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

ll.LoginDatetime = (*time.Time)(p.LoginDatetime)

return nil
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (i *User) UnmarshalJSON(b []byte) error {
type Mask User
Expand Down

0 comments on commit a424a08

Please sign in to comment.