Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support building on windows #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions kernel_freebsd.go
Original file line number Diff line number Diff line change
@@ -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() {
}
11 changes: 11 additions & 0 deletions kernel_windows.go
Original file line number Diff line number Diff line change
@@ -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() {
}
13 changes: 13 additions & 0 deletions network_darwin.go
Original file line number Diff line number Diff line change
@@ -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() {
}
13 changes: 13 additions & 0 deletions network_freebsd.go
Original file line number Diff line number Diff line change
@@ -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() {
}
File renamed without changes.
13 changes: 13 additions & 0 deletions network_windows.go
Original file line number Diff line number Diff line change
@@ -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() {
}
10 changes: 5 additions & 5 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}