40 lines
685 B
Go
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
|
|
}
|