discordBots/cmd/vcbot/config/apple.go
2023-04-23 00:33:20 +02:00

40 lines
685 B
Go

package config
import (
"encoding/json"
"io"
"log"
"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))
return nil
}