From d4e648e2536451c12165a80470336b34f011f054 Mon Sep 17 00:00:00 2001 From: Nikolay Sivko Date: Mon, 23 Nov 2015 12:44:35 +0300 Subject: [PATCH 1/2] [freebsd] fix SwapMemory for hosts without swap --- mem/mem_freebsd.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mem/mem_freebsd.go b/mem/mem_freebsd.go index 5746779..e0aabef 100644 --- a/mem/mem_freebsd.go +++ b/mem/mem_freebsd.go @@ -91,7 +91,6 @@ func SwapMemory() (*SwapMemoryStat, error) { if err != nil { return nil, err } - var ret *SwapMemoryStat for _, line := range strings.Split(string(out), "\n") { values := strings.Fields(line) // skip title line @@ -117,13 +116,13 @@ func SwapMemory() (*SwapMemoryStat, error) { return nil, err } - ret = &SwapMemoryStat{ + return &SwapMemoryStat{ Total: total_v, Used: used_v, Free: free_v, UsedPercent: up_v, - } + }, nil } - return ret, nil + return nil, errors.New("no swap devices found") } From 075839d9f1e894759537f5a068066722e2ab04c8 Mon Sep 17 00:00:00 2001 From: Nikolay Sivko Date: Wed, 25 Nov 2015 10:50:51 +0300 Subject: [PATCH 2/2] fix imports --- mem/mem_freebsd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mem/mem_freebsd.go b/mem/mem_freebsd.go index e0aabef..0cb33ab 100644 --- a/mem/mem_freebsd.go +++ b/mem/mem_freebsd.go @@ -6,7 +6,7 @@ import ( "os/exec" "strconv" "strings" - + "errors" "github.com/shirou/gopsutil/internal/common" )