summaryrefslogtreecommitdiff
path: root/brewapi.go
diff options
context:
space:
mode:
Diffstat (limited to 'brewapi.go')
-rw-r--r--brewapi.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/brewapi.go b/brewapi.go
new file mode 100644
index 0000000..d520733
--- /dev/null
+++ b/brewapi.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "net/http"
+ "io"
+ "encoding/json"
+ "github.com/fatih/color"
+)
+
+func GetFormulaFromAPI(pkg string) (*FormulaInfo) {
+ resp, err := http.Get("https://formulae.brew.sh/api/formula/" + pkg + ".json")
+ if err != nil {
+ print(err)
+ color.Red("❌ Error fetching formula info from brew.sh")
+ return nil
+ }
+ defer resp.Body.Close()
+ body, err := io.ReadAll(resp.Body)
+
+ var data FormulaInfo
+ if err := json.Unmarshal(body, &data); err != nil {
+ color.Red("❌ Error parsing API response from brew.sh")
+ }
+
+ return &data
+}
+
+func GetCaskFromAPI(pkg string) (*CaskInfo) {
+ resp, err := http.Get("https://formulae.brew.sh/api/cask/" + pkg + ".json")
+ if err != nil {
+ color.Red("❌ Error fetching formula info from brew.sh")
+ return nil
+ }
+ defer resp.Body.Close()
+ body, err := io.ReadAll(resp.Body)
+
+ var data CaskInfo
+ if err := json.Unmarshal(body, &data); err != nil {
+ color.Red("❌ Error parsing API response from brew.sh")
+ }
+
+ return &data
+}