Skip to content

Commit

Permalink
support building on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fffaraz committed Jan 8, 2024
1 parent 30169cf commit 16235a2
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 10 deletions.
2 changes: 0 additions & 2 deletions kernel_darwin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//+build darwin

package sysinfo

// Kernel information.
Expand Down
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() {
}
2 changes: 0 additions & 2 deletions kernel_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
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)
}

0 comments on commit 16235a2

Please sign in to comment.