forked from k5342/ikabot3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.go
74 lines (62 loc) · 1.38 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"encoding/json"
"io"
"net/http"
"os"
"time"
)
// https://spla3.yuu26.com/api/schedule
type AllAPIResult struct {
Result AllScheduleInfo `json:"result"`
}
type AllScheduleInfo struct {
Regular []TimeSlotInfo `json:"regular"`
BankaraChallenge []TimeSlotInfo `json:"bankara_challenge"`
BankaraOpen []TimeSlotInfo `json:"bankara_open"`
}
type TimeSlotInfo struct {
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Rule RuleInfo `json:"rule"`
Stages []StageInfo `json:"stages"`
IsFest bool `json:"is_fest"`
}
type RuleInfo struct {
Key string `json:"key"`
Name string `json:"name"`
}
type StageInfo struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
func fetchAll() (*AllAPIResult, error) {
url := os.Getenv("IKABOT3_API_SOURCE")
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Add("User-Agent", USER_AGENT)
client := http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var ar AllAPIResult
err = json.Unmarshal(bytes, &ar)
if err != nil {
return nil, err
}
return &ar, nil
}
func FetchScheduleInfo() (*AllScheduleInfo, error) {
result, err := fetchAll()
if err != nil {
return nil, err
}
return &result.Result, nil
}