-
Notifications
You must be signed in to change notification settings - Fork 0
/
response-parser.go
61 lines (48 loc) · 1.14 KB
/
response-parser.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
package main
import (
"encoding/json"
"io"
"net/http"
)
type TeamsResponse struct {
Teams []struct {
TeamNumber int `json:"teamNumber"`
NameShort string `json:"nameShort"`
} `json:"teams"`
TeamCountPage int `json:"teamCountPage"`
PageCurrent int `json:"pageCurrent"`
PageTotal int `json:"pageTotal"`
}
type ScheduleResponse struct {
Schedule []struct {
MatchNumber int `json:"matchNumber"`
Teams []struct {
TeamNumber int `json:"teamNumber"`
Station string `json:"station"`
} `json:"teams"`
} `json:"schedule"`
}
func ParseTeamsResponse(resp *http.Response) (TeamsResponse, error) {
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return TeamsResponse{}, err
}
var out TeamsResponse
if err = json.Unmarshal(body, &out); err != nil {
panic(err)
}
return out, nil
}
func ParseScheduleResponse(resp *http.Response) (ScheduleResponse, error) {
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return ScheduleResponse{}, err
}
var out ScheduleResponse
if err = json.Unmarshal(body, &out); err != nil {
panic(err)
}
return out, nil
}