Skip to content

Commit

Permalink
feat: add a hex field to Id types
Browse files Browse the repository at this point in the history
Helps address issues brought up in numtide/nixos-facter-modules#58 by introducing an additional hex field in the Id type.

Eventually, we can make this a breaking change by removing the value field and incrementing the report version.

This is a chance to test out how we can introduce breaking changes, whilst allowing module authors time to update.

Closes #141

Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee authored and mergify[bot] committed Nov 7, 2024
1 parent e7a78e2 commit ccbe441
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/hwinfo/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,28 @@ type Id struct {
Name string
}

type idJson struct {
Hex string `json:"hex,omitempty"`
Name string `json:"name,omitempty"`
Value uint16 `json:"value"`
}

func (i Id) MarshalJSON() ([]byte, error) {
switch i.Type {

case IdTagSpecial:
return json.Marshal(i.Name)
default:
return json.Marshal(struct {
Name string `json:"name,omitempty"`
Value uint16 `json:"value"`
}{

case 0, IdTagPci, IdTagEisa, IdTagUsb, IdTagPcmcia, IdTagSdio:

return json.Marshal(idJson{
Hex: fmt.Sprintf("%04x", i.Value),
Name: i.Name,
Value: i.Value,
})

default:
return nil, fmt.Errorf("unknown id type %d", i.Type)
}
}

Expand Down

0 comments on commit ccbe441

Please sign in to comment.