Skip to content

Commit

Permalink
Adding built field to LinodeKernel (#355)
Browse files Browse the repository at this point in the history
* adding `Built` field

* formatting
  • Loading branch information
amisiorek-akamai authored Aug 8, 2023
1 parent ea3b5a8 commit da3a971
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions kernels.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ package linodego

import (
"context"
"encoding/json"
"fmt"
"net/url"
"time"

"github.com/go-resty/resty/v2"
"github.com/linode/linodego/internal/parseabletime"
)

// LinodeKernel represents a Linode Instance kernel object
type LinodeKernel struct {
ID string `json:"id"`
Label string `json:"label"`
Version string `json:"version"`
Architecture string `json:"architecture"`
Deprecated bool `json:"deprecated"`
KVM bool `json:"kvm"`
XEN bool `json:"xen"`
PVOPS bool `json:"pvops"`
ID string `json:"id"`
Label string `json:"label"`
Version string `json:"version"`
Architecture string `json:"architecture"`
Deprecated bool `json:"deprecated"`
KVM bool `json:"kvm"`
XEN bool `json:"xen"`
PVOPS bool `json:"pvops"`
Built *time.Time `json:"-"`
}

// LinodeKernelsPagedResponse represents a Linode kernels API response for listing
Expand All @@ -26,6 +30,26 @@ type LinodeKernelsPagedResponse struct {
Data []LinodeKernel `json:"data"`
}

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

p := struct {
*Mask
Built *parseabletime.ParseableTime `json:"built"`
}{
Mask: (*Mask)(i),
}

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

i.Built = (*time.Time)(p.Built)

return nil
}

func (LinodeKernelsPagedResponse) endpoint(_ ...any) string {
return "linode/kernels"
}
Expand Down

0 comments on commit da3a971

Please sign in to comment.