Skip to content

Commit

Permalink
fix the ID
Browse files Browse the repository at this point in the history
  • Loading branch information
codemodify committed Mar 3, 2020
1 parent 890afdf commit 6053e0c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cpu-unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"),
Expand All @@ -50,6 +51,10 @@ func Info() CPU {
},
}

if len(strings.TrimSpace(cpuInfo.Model)) == 0 {
cpuInfo.Model = fetchCPUInfo("model name")
}

cpuInfo.setID()

return cpuInfo
Expand Down Expand Up @@ -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"`
}
Expand Down
5 changes: 4 additions & 1 deletion cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"

"golang.org/x/crypto/sha3"
)
Expand All @@ -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"` //
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
5 changes: 4 additions & 1 deletion tests/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 6053e0c

Please sign in to comment.