Browse Source

pkg/sysinfo: unify ReadMemInfo implementation

Use a single exported implementation, so that we can maintain the
GoDoc string in one place, and use non-exported functions for the
actual implementation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 years ago
parent
commit
ec878a3d89

+ 7 - 0
pkg/sysinfo/meminfo.go

@@ -1,5 +1,12 @@
 package sysinfo
 
+// ReadMemInfo retrieves memory statistics of the host system and returns a
+// Memory type. It is only supported on Linux and Windows, and returns an
+// error on other platforms.
+func ReadMemInfo() (*Memory, error) {
+	return readMemInfo()
+}
+
 // Memory contains memory statistics of the host system.
 type Memory struct {
 	// Total usable RAM (i.e. physical RAM minus a few reserved bits and the

+ 2 - 2
pkg/sysinfo/meminfo_linux.go

@@ -8,9 +8,9 @@ import (
 	"strings"
 )
 
-// ReadMemInfo retrieves memory statistics of the host system and returns a
+// readMemInfo retrieves memory statistics of the host system and returns a
 // Memory type.
-func ReadMemInfo() (*Memory, error) {
+func readMemInfo() (*Memory, error) {
 	file, err := os.Open("/proc/meminfo")
 	if err != nil {
 		return nil, err

+ 2 - 2
pkg/sysinfo/meminfo_unsupported.go

@@ -5,7 +5,7 @@ package sysinfo
 
 import "errors"
 
-// ReadMemInfo is not supported on platforms other than linux and windows.
-func ReadMemInfo() (*Memory, error) {
+// readMemInfo is not supported on platforms other than linux and windows.
+func readMemInfo() (*Memory, error) {
 	return nil, errors.New("platform and architecture is not supported")
 }

+ 1 - 1
pkg/sysinfo/meminfo_windows.go

@@ -28,7 +28,7 @@ type memorystatusex struct {
 
 // ReadMemInfo retrieves memory statistics of the host system and returns a
 // Memory type.
-func ReadMemInfo() (*Memory, error) {
+func readMemInfo() (*Memory, error) {
 	msi := &memorystatusex{
 		dwLength: 64,
 	}