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 }