refactor vcbot to packages
This commit is contained in:
parent
8a4c903c08
commit
21c6e7a748
5 changed files with 265 additions and 237 deletions
40
cmd/vcbot/config/apple.go
Normal file
40
cmd/vcbot/config/apple.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue