Created
August 4, 2024 01:55
-
-
Save portlandhodl/ec125b80490cc965481bc4ed17723d06 to your computer and use it in GitHub Desktop.
Waybar Bitaxe Difficulty Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io" | |
"net/http" | |
) | |
type SystemInfo struct { | |
BestDiff string `json:"bestDiff"` | |
} | |
func main() { | |
url := "http://192.168.2.82/api/system/info" | |
req, err := http.NewRequest("GET", url, nil) | |
if err != nil { | |
return | |
} | |
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0") | |
req.Header.Set("Accept", "application/json, text/plain, */*") | |
req.Header.Set("Accept-Language", "en-US,en;q=0.5") | |
req.Header.Set("DNT", "1") | |
req.Header.Set("Sec-GPC", "1") | |
req.Header.Set("Connection", "keep-alive") | |
req.Header.Set("Referer", "http://192.168.2.82/") | |
client := &http.Client{} | |
resp, err := client.Do(req) | |
if err != nil { | |
return | |
} | |
defer resp.Body.Close() | |
body, err := io.ReadAll(resp.Body) | |
if err != nil { | |
return | |
} | |
var info SystemInfo | |
err = json.Unmarshal(body, &info) | |
if err != nil { | |
return | |
} | |
fmt.Println(info.BestDiff) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment