Skip to content

Commit

Permalink
json: Simplify unmarshalBootloader
Browse files Browse the repository at this point in the history
This commit is doing the same simplification as was done in the previous
commit.

Signed-off-by: Christophe Fergeau <[email protected]>
  • Loading branch information
cfergeau authored and baude committed Jun 26, 2023
1 parent 7bc4747 commit bfc5016
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions pkg/config/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,23 @@ func kind(k vmComponentKind) jsonKind {

func unmarshalBootloader(rawMsg json.RawMessage) (Bootloader, error) {
var (
kind string
blmap map[string]*json.RawMessage
kind jsonKind
bootloader Bootloader
err error
)
if err := json.Unmarshal(rawMsg, &blmap); err != nil {
return nil, err
}

rawKind := blmap["kind"]
if rawKind == nil {
return nil, fmt.Errorf("missing 'kind' node")
}
if err := json.Unmarshal(*rawKind, &kind); err != nil {
return nil, err
}
delete(blmap, "kind")
b, err := json.Marshal(blmap)
if err != nil {
if err := json.Unmarshal(rawMsg, &kind); err != nil {
return nil, err
}
switch kind {
case string(efiBootloader):
switch kind.Kind {
case efiBootloader:
var efi EFIBootloader
err = json.Unmarshal(b, &efi)
err = json.Unmarshal(rawMsg, &efi)
if err == nil {
bootloader = &efi
}
case string(linuxBootloader):
case linuxBootloader:
var linux LinuxBootloader
err = json.Unmarshal(b, &linux)
err = json.Unmarshal(rawMsg, &linux)
if err == nil {
bootloader = &linux
}
Expand Down

0 comments on commit bfc5016

Please sign in to comment.