skeleton for testing purposes

This commit is contained in:
lin committed 2026-10-05 14:17:03 +02:00
1 parent 8076b30e3f
commit 71e4f1294e
11 files changed
+273

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
package system_check
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
)
var numberRegex *regexp.Regexp = regexp.MustCompile(`\d+`)
func getLinuxRamInfo() (MemoryInformation, error) {
memoryFile, err := os.Open("/proc/meminfo")
if err != nil {
return MemoryInformation{}, fmt.Errorf("Could not find /proc/meminfo. Are you sure you are on linux?")
}
fileReader := bufio.NewScanner(memoryFile)
var TotalMemory uint64
var AvailMemory uint64
for fileReader.Scan() {
if fileReader.Err() != nil {
return MemoryInformation{}, fmt.Errorf("There was an error while reading /proc/meninfo. Error: %v", fileReader.Err())
}
line := fileReader.Text()
if strings.Contains(line, "MemTotal") {
TotalMemory, err = strconv.ParseUint(numberRegex.FindString(line), 10, 64)
if err != nil {
return MemoryInformation{}, fmt.Errorf("Could not parse total memory from /proc/meminfo")
}
} else if strings.Contains(line, "MemAvailable") {
AvailMemory, err = strconv.ParseUint(numberRegex.FindString(line), 10, 64)
if err != nil {
return MemoryInformation{}, fmt.Errorf("Could not parse available memory from /proc/meminfo")
}
}
}
return MemoryInformation{
SystemMemory: TotalMemory,
AvailableMemory: AvailMemory,
}, nil
}