Skip to content

Commit 6161b0a

Browse files
authored
Merge pull request #93 from Akilan1999/abstracted-functions
modified server specs to return type ServerSpec instead of interface.
2 parents 60a00cb + 4268b5a commit 6161b0a

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

server/gopsutil.go

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
package server
22

33
import (
4-
"github.com/shirou/gopsutil/v3/cpu"
5-
"github.com/shirou/gopsutil/v3/disk"
6-
"github.com/shirou/gopsutil/v3/host"
7-
"github.com/shirou/gopsutil/v3/mem"
4+
"github.com/shirou/gopsutil/v3/cpu"
5+
"github.com/shirou/gopsutil/v3/disk"
6+
"github.com/shirou/gopsutil/v3/host"
7+
"github.com/shirou/gopsutil/v3/mem"
88
)
99

1010
// SysInfo saves the basic system information
1111
type SysInfo struct {
12-
Hostname string `bson:hostname`
13-
Platform string `bson:platform`
14-
CPU string `bson:cpu`
15-
RAM uint64 `bson:ram`
16-
Disk uint64 `bson:disk`
17-
GPU *Query `xml: GpuInfo`
12+
Hostname string `bson:hostname`
13+
Platform string `bson:platform`
14+
CPU string `bson:cpu`
15+
RAM uint64 `bson:ram`
16+
Disk uint64 `bson:disk`
17+
GPU *Query `xml: GpuInfo`
1818
}
1919

20-
func ServerInfo() interface{} {
21-
hostStat, _ := host.Info()
22-
cpuStat, _ := cpu.Info()
23-
vmStat, _ := mem.VirtualMemory()
20+
func ServerInfo() *SysInfo {
21+
hostStat, _ := host.Info()
22+
cpuStat, _ := cpu.Info()
23+
vmStat, _ := mem.VirtualMemory()
2424

25-
info := new(SysInfo)
25+
info := new(SysInfo)
2626

27-
filesystem := "/"
27+
filesystem := "/"
2828

29-
// If the server is running windows
30-
if info.Hostname == "windows" {
31-
filesystem = "\\"
32-
}
29+
// If the server is running windows
30+
if info.Hostname == "windows" {
31+
filesystem = "\\"
32+
}
3333

34-
diskStat, _ := disk.Usage(filesystem) // If you're in Unix change this "\\" for "/"
34+
diskStat, _ := disk.Usage(filesystem) // If you're in Unix change this "\\" for "/"
3535

36-
info.Hostname = hostStat.Hostname
37-
info.Platform = hostStat.Platform
38-
info.CPU = cpuStat[0].ModelName
39-
info.RAM = vmStat.Total / 1024 / 1024
40-
info.Disk = diskStat.Total / 1024 / 1024
36+
info.Hostname = hostStat.Hostname
37+
info.Platform = hostStat.Platform
38+
info.CPU = cpuStat[0].ModelName
39+
info.RAM = vmStat.Total / 1024 / 1024
40+
info.Disk = diskStat.Total / 1024 / 1024
4141

42-
gpu, err := GPUInfo()
42+
gpu, err := GPUInfo()
4343

44-
if err == nil {
45-
info.GPU = gpu
46-
}
44+
if err == nil {
45+
info.GPU = gpu
46+
}
4747

48-
return info
48+
return info
4949

5050
}

0 commit comments

Comments
 (0)