func (mg *MailgunImpl) ListEvents(opts *EventsOptions) *EventIterator {
	req := newHTTPRequest(generateApiUrl(mg, eventsEndpoint))
	if opts != nil {
		if opts.Limit != 0 {
			req.addParameter("limit", fmt.Sprintf("%d", opts.Limit))
		}
		if opts.Compact {
			req.addParameter("pretty", "no")
		}
		if opts.ForceAscending {
			req.addParameter("ascending", "yes")
		}
		if opts.ForceDescending {
			req.addParameter("ascending", "no")
		}
		if opts.Begin != noTime {
			req.addParameter("begin", formatMailgunTime(&opts.Begin))
		}
		if opts.End != noTime {
			req.addParameter("end", formatMailgunTime(&opts.End))
		}
		if opts.Filter != nil {
			for k, v := range opts.Filter {
				req.addParameter(k, v)
			}
		}
	}
	url, err := req.generateUrlWithParameters()
	return &EventIterator{
		mg:       mg,
		NextURL:  url,
		FirstURL: url,
		PrevURL:  "",
		err:      err,
	}
}
Create an new iterator to fetch a page of events from the events api
it := mg.ListEvents(EventsOptions{})
var events []Event
for it.Next(&events) {
for _, event := range events {
// Do things with events
}
}
if it.Err() != nil {
log.Fatal(it.Err())
}
package mailgun
import (
	"fmt"
	"time"
	"github.com/pkg/errors"
)
type Event map[string]interface{}
func (e Event) ParseTimeStamp() (time.Time, error) {
	obj, ok := e["timestamp"]
	if !ok {
		return time.Time{}, errors.New("'timestamp' field not found in event")
	}
	timestamp, ok := obj.(float64)
	if !ok {
		return time.Time{}, errors.New("'timestamp' field not a float64")
	}
	microseconds := int64(timestamp * 1000000)
	return time.Unix(0, microseconds*int64(time.Microsecond/time.Nanosecond)).UTC(), nil
}
func (e Event) ParseMessageId() (string, error) {
	message, err := toMapInterface("message", e)
	if err != nil {
		return "", err
	}
	headers, err := toMapInterface("headers", message)
	if err != nil {
		return "", err
	}
	return headers["message-id"].(string), nil
}
var noTime time.Time
type EventsOptions struct {
	Begin, End                               time.Time
	ForceAscending, ForceDescending, Compact bool
	Limit                                    int
	Filter                                   map[string]string
	ThresholdAge                             time.Duration
	PollInterval                             time.Duration
}
type GetEventsOptions struct {
	Begin, End                               time.Time
	ForceAscending, ForceDescending, Compact bool
	Limit                                    int
	Filter                                   map[string]string
}
type EventIterator struct {
	events                              []Event
	NextURL, PrevURL, FirstURL, LastURL string
	mg                                  Mailgun
	err                                 error
}
func (mg *MailgunImpl) NewEventIterator() *EventIterator {
	return &EventIterator{mg: mg}
}