...
1
2
3
4
5
6 package github
7
8 import (
9 "encoding/json"
10 )
11
12
13 type Event struct {
14 Type *string `json:"type,omitempty"`
15 Public *bool `json:"public,omitempty"`
16 RawPayload *json.RawMessage `json:"payload,omitempty"`
17 Repo *Repository `json:"repo,omitempty"`
18 Actor *User `json:"actor,omitempty"`
19 Org *Organization `json:"org,omitempty"`
20 CreatedAt *Timestamp `json:"created_at,omitempty"`
21 ID *string `json:"id,omitempty"`
22 }
23
24 func (e Event) String() string {
25 return Stringify(e)
26 }
27
28
29
30 func (e *Event) ParsePayload() (interface{}, error) {
31
32
33 payload := EventForType(typeToMessageMapping[e.GetType()])
34
35 if err := json.Unmarshal(e.GetRawPayload(), &payload); err != nil {
36 return nil, err
37 }
38
39 return payload, nil
40 }
41
42
43
44
45
46
47 func (e *Event) Payload() (payload interface{}) {
48 var err error
49 payload, err = e.ParsePayload()
50 if err != nil {
51 panic(err)
52 }
53 return payload
54 }
55
View as plain text