discordBots/cmd/vcbot/config/apple.go

50 lines
803 B
Go
Raw Permalink Normal View History

2023-03-08 20:39:42 +00:00
package config
import (
"encoding/json"
"io"
"log"
2023-03-08 20:39:42 +00:00
"net/http"
)
var (
AppleApi = "https://grow.rievo.page/applelist/initial.json"
AppleList []string
)
type appleApiBody struct {
Status string `json:"status"`
Type string `json:"type"`
Version string `json:"version"`
Body []string `json:"body"`
}
func LoadAppleList() error {
res, err := http.Get(AppleApi)
if err != nil {
return err
}
body, err := io.ReadAll(res.Body)
if err != nil {
return err
}
var data appleApiBody
err = json.Unmarshal(body, &data)
if err != nil {
return err
}
AppleList = data.Body
log.Printf("DEBUG: loaded apple list of lenght: %v", len(AppleList))
2023-03-08 20:39:42 +00:00
return nil
}
2024-01-28 19:52:00 +00:00
func FallbackAppleList() {
AppleList = []string{
"Braeburn",
"Gala",
"Golden Delicious",
"Honeycrisp",
}
}