discordBots/cmd/vcbot/config/apple.go

41 lines
695 B
Go
Raw Normal View History

2023-03-08 20:39:42 +00:00
package config
import (
"encoding/json"
"github.com/disgoorg/log"
"io"
"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.Debug("loaded apple list of lenght: ", len(AppleList))
return nil
}