-
Notifications
You must be signed in to change notification settings - Fork 0
/
req.go
53 lines (44 loc) · 990 Bytes
/
req.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
package analyse
import (
"encoding/json"
"io"
"io/ioutil"
"time"
)
type Msg struct {
MsgType string `json:"type"`
Body json.RawMessage `json:"body"`
}
func NewMsgWithReader(mType string, r io.Reader) (*Msg, error) {
bodyBuff, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return &Msg{
MsgType: mType,
Body: bodyBuff,
}, nil
}
func (m *Msg) ParseBody(bType interface{}) (err error) {
return json.Unmarshal(m.Body, bType)
}
type Event struct {
TargetID int `json:"targetID"`
Event string `json:"event"`
Time int64 `json:"time"`
}
func (e *Event) DisplayTime() string {
return time.Unix(e.Time, 0).String()
}
type User struct {
ID int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Address string `json:"address"`
}
type Item struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Price int `json:"price"`
}