forked from clockworksoul/mediawiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.go
More file actions
92 lines (78 loc) · 2.44 KB
/
Copy pathresponse.go
File metadata and controls
92 lines (78 loc) · 2.44 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package mediawiki
import (
"encoding/json"
"io"
"time"
)
type CoreResponse struct {
RawJSON string `json:"-"`
ClientLogin *ResponseClientLogin `json:"clientlogin,omitempty"`
Error *ResponseError `json:"error,omitempty"`
Warnings map[string]ResponseError `json:"warnings,omitempty"`
}
type Response struct {
CoreResponse
RawJSON string `json:"-"`
BatchComplete any `json:"batchcomplete,omitempty"`
BotLogin *ResponseBotLogin `json:"login,omitempty"`
ClientLogin *ResponseClientLogin `json:"clientlogin,omitempty"`
Edit *ResponseEdit `json:"edit,omitempty"`
Query *ResponseQuery `json:"query,omitempty"`
Warnings *ResponseWarnings `json:"warnings,omitempty"`
}
type ResponseError struct {
Code string `json:"code,omitempty"`
Docref string `json:"docref,omitempty"`
Info string `json:"info,omitempty"`
Stasherrors []struct {
Message string `json:"message,omitempty"`
Params []string `json:"params,omitempty"`
Code string `json:"code,omitempty"`
Type string `json:"type,omitempty"`
} `json:"stasherrors,omitempty"`
Star string `json:"*,omitempty"`
}
type ResponseQuery struct {
Pages []QueryResponseQueryPage `json:"pages"`
Tokens map[string]string `json:"tokens"`
}
type ResponseWarnings struct {
Tokens map[string]string `json:"tokens"`
}
type ResponseClientLogin struct {
Status string `json:"status"`
Message string `json:"message"`
MessageCode string `json:"messagecode"`
}
type Result string
const (
Error Result = "Error"
Success Result = "Success"
Warning Result = "Warning"
)
type ResponseBotLogin struct {
Result Result `json:"result"`
Reason string `json:"reason"`
UserId int `json:"lguserid"`
UserName string `json:"lgusername"`
}
type ResponseEdit struct {
Result Result `json:"result"`
PageId int `json:"pageid"`
Title string `json:"title"`
ContentModel string `json:"contentmodel"`
OldRevId int `json:"oldrevid,omitempty"`
NewRevId int `json:"newrevid,omitempty"`
NewTimestamp time.Time `json:"newtimestamp,omitempty"`
Watched string `json:"watched"`
}
func ParseResponseReader(in io.Reader, v any) error {
b, err := io.ReadAll(in)
if err != nil {
return err
}
return ParseResponse(b, v)
}
func ParseResponse(b []byte, v any) error {
return json.Unmarshal(b, v)
}