diff --git a/kernel_darwin.go b/kernel_darwin.go index b586896..3c003dd 100644 --- a/kernel_darwin.go +++ b/kernel_darwin.go @@ -1,5 +1,3 @@ -//+build darwin - package sysinfo // Kernel information. diff --git a/kernel_freebsd.go b/kernel_freebsd.go new file mode 100644 index 0000000..3c003dd --- /dev/null +++ b/kernel_freebsd.go @@ -0,0 +1,11 @@ +package sysinfo + +// Kernel information. +type Kernel struct { + Release string `json:"release,omitempty"` + Version string `json:"version,omitempty"` + Architecture string `json:"architecture,omitempty"` +} + +func (si *SysInfo) getKernelInfo() { +} diff --git a/kernel_linux.go b/kernel_linux.go index 64e1b6c..b024215 100644 --- a/kernel_linux.go +++ b/kernel_linux.go @@ -2,8 +2,6 @@ // // Use of this source code is governed by an MIT-style license that can be found in the LICENSE file. -//+build linux - package sysinfo import ( diff --git a/kernel_windows.go b/kernel_windows.go new file mode 100644 index 0000000..3c003dd --- /dev/null +++ b/kernel_windows.go @@ -0,0 +1,11 @@ +package sysinfo + +// Kernel information. +type Kernel struct { + Release string `json:"release,omitempty"` + Version string `json:"version,omitempty"` + Architecture string `json:"architecture,omitempty"` +} + +func (si *SysInfo) getKernelInfo() { +} diff --git a/network_darwin.go b/network_darwin.go new file mode 100644 index 0000000..ecf210a --- /dev/null +++ b/network_darwin.go @@ -0,0 +1,13 @@ +package sysinfo + +// NetworkDevice information. +type NetworkDevice struct { + Name string `json:"name,omitempty"` + Driver string `json:"driver,omitempty"` + MACAddress string `json:"macaddress,omitempty"` + Port string `json:"port,omitempty"` + Speed uint `json:"speed,omitempty"` // device max supported speed in Mbps +} + +func (si *SysInfo) getNetworkInfo() { +} diff --git a/network_freebsd.go b/network_freebsd.go new file mode 100644 index 0000000..ecf210a --- /dev/null +++ b/network_freebsd.go @@ -0,0 +1,13 @@ +package sysinfo + +// NetworkDevice information. +type NetworkDevice struct { + Name string `json:"name,omitempty"` + Driver string `json:"driver,omitempty"` + MACAddress string `json:"macaddress,omitempty"` + Port string `json:"port,omitempty"` + Speed uint `json:"speed,omitempty"` // device max supported speed in Mbps +} + +func (si *SysInfo) getNetworkInfo() { +} diff --git a/network.go b/network_linux.go similarity index 100% rename from network.go rename to network_linux.go diff --git a/network_windows.go b/network_windows.go new file mode 100644 index 0000000..ecf210a --- /dev/null +++ b/network_windows.go @@ -0,0 +1,13 @@ +package sysinfo + +// NetworkDevice information. +type NetworkDevice struct { + Name string `json:"name,omitempty"` + Driver string `json:"driver,omitempty"` + MACAddress string `json:"macaddress,omitempty"` + Port string `json:"port,omitempty"` + Speed uint `json:"speed,omitempty"` // device max supported speed in Mbps +} + +func (si *SysInfo) getNetworkInfo() { +} diff --git a/node.go b/node.go index 480ac0d..a59c8e8 100644 --- a/node.go +++ b/node.go @@ -40,21 +40,21 @@ func (si *SysInfo) getSetMachineID() { } // They both exist, but they don't match! Copy systemd machine id to DBUS machine id. - spewFile(pathDbusMachineID, systemdMachineID, 0444) + spewFile(pathDbusMachineID, systemdMachineID, 0o444) si.Node.MachineID = systemdMachineID return } // Copy DBUS machine id to non-existent systemd machine id. if systemdMachineID == "" && dbusMachineID != "" { - spewFile(pathSystemdMachineID, dbusMachineID, 0444) + spewFile(pathSystemdMachineID, dbusMachineID, 0o444) si.Node.MachineID = dbusMachineID return } // Copy systemd machine id to non-existent DBUS machine id. if systemdMachineID != "" && dbusMachineID == "" { - spewFile(pathDbusMachineID, systemdMachineID, 0444) + spewFile(pathDbusMachineID, systemdMachineID, 0o444) si.Node.MachineID = systemdMachineID return } @@ -68,8 +68,8 @@ func (si *SysInfo) getSetMachineID() { } newMachineID := fmt.Sprintf("%x%x", random, time.Now().Unix()) - spewFile(pathSystemdMachineID, newMachineID, 0444) - spewFile(pathDbusMachineID, newMachineID, 0444) + spewFile(pathSystemdMachineID, newMachineID, 0o444) + spewFile(pathDbusMachineID, newMachineID, 0o444) si.Node.MachineID = newMachineID } diff --git a/sysinfo.go b/sysinfo.go index 30b851d..f56ebb9 100644 --- a/sysinfo.go +++ b/sysinfo.go @@ -5,6 +5,8 @@ // Package sysinfo is a Go library providing Linux OS / kernel / hardware system information. package sysinfo +import "runtime" + // SysInfo struct encapsulates all other information structs. type SysInfo struct { Meta Meta `json:"sysinfo"` @@ -23,6 +25,10 @@ type SysInfo struct { // GetSysInfo gathers all available system information. func (si *SysInfo) GetSysInfo() { + if runtime.GOOS != "linux" { + return + } + // Meta info si.getMetaInfo() diff --git a/util.go b/util.go index cd499a4..3a9ad8b 100644 --- a/util.go +++ b/util.go @@ -21,6 +21,6 @@ func slurpFile(path string) string { } // Write one-liner text files, add newline, ignore errors (best effort). -func spewFile(path string, data string, perm os.FileMode) { +func spewFile(path, data string, perm os.FileMode) { _ = ioutil.WriteFile(path, []byte(data+"\n"), perm) }