diff --git a/cpu-unix.go b/cpu-unix.go index 180a372..b2f077b 100644 --- a/cpu-unix.go +++ b/cpu-unix.go @@ -36,6 +36,7 @@ func Info() CPU { Detailed: getCPUVariantDetailed(), }, Manufacturer: fetchCPUInfo2("Vendor ID:"), + Model: fetchCPUInfo2("Model name:"), ByteOrder: fetchCPUInfo2("Byte Order:"), Features: []string{ fetchCPUInfo2("Flags:"), @@ -50,6 +51,10 @@ func Info() CPU { }, } + if len(strings.TrimSpace(cpuInfo.Model)) == 0 { + cpuInfo.Model = fetchCPUInfo("model name") + } + cpuInfo.setID() return cpuInfo @@ -86,11 +91,13 @@ func fetchCPUInfo(pattern string) string { return "" } +// LscpuFieldData - type LscpuFieldData struct { Field string `json:"field"` Data string `json:"data"` } +// LscpuOutput - type LscpuOutput struct { Lscpu []LscpuFieldData `json:"lscpu"` } diff --git a/cpu.go b/cpu.go index aab4d22..7a64bee 100644 --- a/cpu.go +++ b/cpu.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "encoding/hex" + "fmt" "golang.org/x/crypto/sha3" ) @@ -21,6 +22,7 @@ type CPU struct { Architecture CPUArchitecture `json:"architecture,omitempty"` // ex: `amd64` or `ppc64` Variant CPUVariant `json:"variant,omitempty"` // Manufacturer string `json:"manufacturer,omitempty"` // intel, amd, arm + Model string `json:"model,omitempty"` // Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz ByteOrder string `json:"byteOrder,omitempty"` // Features []string `json:"features,omitempty"` // ex: `SWPB (swap) instructions` for ARM AdditionalInfo AdditionalInfo `json:"additionalInfo,omitempty"` // @@ -35,11 +37,12 @@ func (thisRef *CPU) setID() { thisRef.Architecture, thisRef.Variant, thisRef.Manufacturer, + thisRef.Model, thisRef.ByteOrder, } buffer := new(bytes.Buffer) for _, value := range values { - err := binary.Write(buffer, binary.BigEndian, value) + err := binary.Write(buffer, binary.BigEndian, []byte(fmt.Sprintf("%v", value))) if err != nil { return } diff --git a/go.mod b/go.mod index 109dba7..be1c829 100644 --- a/go.mod +++ b/go.mod @@ -6,4 +6,5 @@ require ( github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d github.com/codemodify/systemkit-platform v1.1.0 github.com/go-ole/go-ole v1.2.4 // indirect + golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 ) diff --git a/go.sum b/go.sum index 0423e15..b92693f 100644 --- a/go.sum +++ b/go.sum @@ -4,3 +4,11 @@ github.com/codemodify/systemkit-platform v1.1.0 h1:g1umNTjVaURmhUdqogZKL/HYSdxE4 github.com/codemodify/systemkit-platform v1.1.0/go.mod h1:HdMgbCPaxP4dTx9LvmQdg3X4lIa5St3erhUgtQMH01s= github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI= github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/tests/linux_test.go b/tests/linux_test.go index c415a15..42f3345 100644 --- a/tests/linux_test.go +++ b/tests/linux_test.go @@ -12,7 +12,10 @@ import ( ) func TestCPUVariant(t *testing.T) { - data, err := json.Marshal(platformCPU.Info()) + cpuInfo := platformCPU.Info() + fmt.Println(cpuInfo.ID) + + data, err := json.Marshal(cpuInfo) if err != nil { fmt.Println(err.Error()) t.Fatal(err.Error())