breto

A status bar written in Go.
Log | Files | Refs | README | LICENSE

commit 761f18d0a47f71777d3cdb01a8907ef9dc4c9bd7
parent 177d16301d6aa9652bb5f542dd6b1c74bd3bb47f
Author: Jaron Swab <jrswab@gmail.com>
Date:   Fri, 24 May 2019 17:33:14 -0400

Changed errors from fmt.Println or a custom string to the text of err

Diffstat:
Mlibs/ram/ram.go | 5++++-
Mlibs/wttr/wttr.go | 9+++++----
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libs/ram/ram.go b/libs/ram/ram.go @@ -6,10 +6,13 @@ import ( ) func Free() string { + // set shell command ramCmd := "free -h | gawk '/Mem:/ {print $4}'" + // run and save the output of ramCmd to ramGib ramGib, err := exec.Command("sh", "-c", ramCmd).Output() if err != nil { - return "Error in 'free -h' command." + return err.Error() } + // return ramGib as string return strings.TrimSpace(string(ramGib)) } diff --git a/libs/wttr/wttr.go b/libs/wttr/wttr.go @@ -1,19 +1,20 @@ package wttr import ( - "fmt" "io/ioutil" "net/http" "strings" ) func Local() string { - resp, err := http.Get("https://wttr.in/?format=%t+%w") + // for more wttr options see https://wttr.in/:help + resp, err := http.Get("https://wttr.in/?format=%t+%w") // get temp and wind direction/speed if err != nil { - fmt.Println(err) + return err.Error() } - defer resp.Body.Close() + defer resp.Body.Close() // close http request + // convert responce to string for return bodyData, _ := ioutil.ReadAll(resp.Body) return strings.TrimSpace(string(bodyData)) }