summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2022-12-16 15:17:03 +0100
committerSebastiaan van Stijn <github@gone.nl>2022-12-21 10:53:45 +0100
commitec878a3d895a635e1fefaa27efe83869a1b6b601 (patch)
tree27fbf37f9fb90b1c4249994eb9c84577251e05fc /pkg
parent09ea6744fe4b530e76efdf1df1e39138432c2e39 (diff)
downloaddocker-ec878a3d895a635e1fefaa27efe83869a1b6b601.tar.gz
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>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/sysinfo/meminfo.go7
-rw-r--r--pkg/sysinfo/meminfo_linux.go4
-rw-r--r--pkg/sysinfo/meminfo_unsupported.go4
-rw-r--r--pkg/sysinfo/meminfo_windows.go2
4 files changed, 12 insertions, 5 deletions
diff --git a/pkg/sysinfo/meminfo.go b/pkg/sysinfo/meminfo.go
index 7cdd996bfd..6b9f8e5505 100644
--- a/pkg/sysinfo/meminfo.go
+++ b/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
diff --git a/pkg/sysinfo/meminfo_linux.go b/pkg/sysinfo/meminfo_linux.go
index ef4f4ac242..993be58450 100644
--- a/pkg/sysinfo/meminfo_linux.go
+++ b/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
diff --git a/pkg/sysinfo/meminfo_unsupported.go b/pkg/sysinfo/meminfo_unsupported.go
index 9f977b022a..42472dda71 100644
--- a/pkg/sysinfo/meminfo_unsupported.go
+++ b/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")
}
diff --git a/pkg/sysinfo/meminfo_windows.go b/pkg/sysinfo/meminfo_windows.go
index cfc1d059a4..553c1f3f4c 100644
--- a/pkg/sysinfo/meminfo_windows.go
+++ b/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,
}