forked from riobard/go-mailgun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
43 lines (37 loc) · 811 Bytes
/
log.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
package mailgun
import (
"encoding/json"
"net/url"
"strconv"
"time"
)
type Log struct {
Hap string `json:"hap"`
CreatedAt string `json:"created_at"`
Message string `json:"message"`
Type string `json:"type"`
MessageId string `json:"message_id"`
}
func (l Log) Time() time.Time {
t, _ := time.Parse(time.RFC1123, l.CreatedAt)
return t
}
func (mg Mailgun) Logs(domain string, limit, skip int) (total int, res []Log, err error) {
v := url.Values{}
v.Set("limit", strconv.Itoa(limit))
v.Set("skip", strconv.Itoa(skip))
body, err := mg.api("GET", "/"+domain+"/log", v)
if err != nil {
return
}
var j struct {
Total int `json:"total_count"`
Items []Log `json:"items"`
}
err = json.Unmarshal(body, &j)
if err != nil {
return
}
total, res = j.Total, j.Items
return
}