diff --git a/kernels.go b/kernels.go index 0c4246f5f..26987a639 100644 --- a/kernels.go +++ b/kernels.go @@ -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 @@ -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" }