breto

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

commit 177d16301d6aa9652bb5f542dd6b1c74bd3bb47f
parent c73c73dec04d8edcde6a40101b31c9a34a01b721
Author: J. R. Swab <jrswab@protonmail.com>
Date:   Fri, 24 May 2019 20:39:03 +0000

Merge branch 'nativeGoWttr' into 'master'

Changed weather report to Go native syntax.

See merge request jrswab/dwm-status!4
Diffstat:
Mlibs/wttr/wttr.go | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/libs/wttr/wttr.go b/libs/wttr/wttr.go @@ -1,15 +1,19 @@ package wttr import ( - "os/exec" + "fmt" + "io/ioutil" + "net/http" "strings" ) func Local() string { - wttrCmd := "curl -s 'wttr.in/?format=%t+%w'" - wttrRun, err := exec.Command("sh", "-c", wttrCmd).Output() + resp, err := http.Get("https://wttr.in/?format=%t+%w") if err != nil { - return "wttr command returned error!" + fmt.Println(err) } - return strings.TrimSpace(string(wttrRun)) + defer resp.Body.Close() + + bodyData, _ := ioutil.ReadAll(resp.Body) + return strings.TrimSpace(string(bodyData)) }