-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpciid.go
47 lines (38 loc) · 1.06 KB
/
pciid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package pciids
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
)
// PCIID struct.
type PCIID struct {
VendorID string `json:"vendorId"`
VendorName string `json:"vendorName"`
DeviceID string `json:"deviceId"`
DeviceName string `json:"deviceName"`
SubVendorID string `json:"subvendorId,omitempty"`
SubVendorName string `json:"subvendorName,omitempty"`
SubDeviceID string `json:"subdeviceId,omitempty"`
SubDeviceName string `json:"subdeviceName,omitempty"`
}
// String representation of the struct.
func (p *PCIID) String() string {
if (p.SubVendorID != "") && (p.SubDeviceID != "") {
return fmt.Sprintf(
"%s:%s %s:%s - %s %s",
p.VendorID, p.DeviceID, p.SubVendorID, p.SubDeviceID, p.SubVendorName, p.SubDeviceName,
)
}
return fmt.Sprintf(
"%s:%s - %s %s", p.VendorID, p.DeviceID, p.VendorName, p.DeviceName,
)
}
// JSON representation of the struct.
func (p *PCIID) JSON() string {
bytes, err := json.MarshalIndent(&p, "", " ")
if err != nil {
log.Error("error marshaling JSON:", err)
return ""
}
return string(bytes)
}