mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
package system
|
|
|
|
import (
|
|
"os/exec"
|
|
"runtime"
|
|
"strings"
|
|
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
type SystemInfo struct {
|
|
ProductName string
|
|
ProductVersion string
|
|
BuildVersion string
|
|
}
|
|
|
|
func NewSystemInfo() *SystemInfo {
|
|
m := make(map[string]string)
|
|
|
|
arg := []string{}
|
|
|
|
var cmd *exec.Cmd
|
|
switch runtime.GOOS {
|
|
case "linux":
|
|
cmd = exec.Command("uname -a", arg...)
|
|
case "darwin":
|
|
cmd = exec.Command("sw_vers", arg...)
|
|
default:
|
|
cmd = exec.Command("sw_vers", arg...)
|
|
}
|
|
|
|
raw := wtf.ExecuteCommand(cmd)
|
|
|
|
for _, row := range strings.Split(raw, "\n") {
|
|
parts := strings.Split(row, ":")
|
|
|
|
if len(parts) < 2 {
|
|
continue
|
|
}
|
|
|
|
m[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
|
|
}
|
|
|
|
sysInfo := new(SystemInfo)
|
|
switch runtime.GOOS {
|
|
case "linux":
|
|
sysInfo = &SystemInfo{
|
|
ProductName: m["Distributor ID"],
|
|
ProductVersion: m["Description"],
|
|
BuildVersion: m["Release"],
|
|
}
|
|
case "darwin":
|
|
sysInfo = &SystemInfo{
|
|
ProductName: m["ProductName"],
|
|
ProductVersion: m["ProductVersion"],
|
|
BuildVersion: m["BuildVersion"],
|
|
}
|
|
default:
|
|
sysInfo = &SystemInfo{
|
|
ProductName: m["ProductName"],
|
|
ProductVersion: m["ProductVersion"],
|
|
BuildVersion: m["BuildVersion"],
|
|
}
|
|
|
|
}
|
|
return sysInfo
|
|
}
|