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>
This commit is contained in:
Sebastiaan van Stijn 2022-12-16 15:17:03 +01:00
parent 09ea6744fe
commit ec878a3d89
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 12 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -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")
}

View file

@ -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,
}