refactor(pty): switch to using interface (#34)
* refactor(pty): switch to using interface for better flexibility (although may not be useful) * chore: reduce error messages * delete redundant messages
This commit is contained in:
+5
-6
@@ -4,25 +4,24 @@
|
||||
package gpu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
"github.com/jaypipes/ghw"
|
||||
)
|
||||
|
||||
func GetGPUModel() []string {
|
||||
func GetGPUModel() ([]string, error) {
|
||||
var gpuModel []string
|
||||
gi, err := ghw.GPU(ghw.WithDisableWarnings())
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting GPU info: %v", err)
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, card := range gi.GraphicsCards {
|
||||
if card.DeviceInfo == nil {
|
||||
return nil
|
||||
return nil, errors.New("Cannot find device info")
|
||||
}
|
||||
gpuModel = append(gpuModel, card.DeviceInfo.Product.Name)
|
||||
}
|
||||
|
||||
return gpuModel
|
||||
return gpuModel, nil
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package gpu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -26,7 +25,7 @@ func extractGPUInfo(cmd *exec.Cmd) ([]string, error) {
|
||||
return modelNames, nil
|
||||
}
|
||||
|
||||
func GetGPUModel() []string {
|
||||
func GetGPUModel() ([]string, error) {
|
||||
vendorNames := []string{
|
||||
"AMD", "Intel", "Nvidia", "Apple",
|
||||
}
|
||||
@@ -37,8 +36,7 @@ func GetGPUModel() []string {
|
||||
ioreg = exec.Command("ioreg", "-rd1", "-c", "IOPCIDevice")
|
||||
gi, err = extractGPUInfo(ioreg)
|
||||
if err != nil {
|
||||
fmt.Println("Error executing ioreg:", err)
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,5 +49,5 @@ func GetGPUModel() []string {
|
||||
}
|
||||
}
|
||||
}
|
||||
return gpuModel
|
||||
return gpuModel, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user