Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding built field to LinodeKernel #355

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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