func (ei *EventIterator) First(events *[]Event) bool {
	if ei.err != nil {
		return false
	}
	ei.err = ei.fetch(ei.FirstURL)
	if ei.err != nil {
		return false
	}
	*events = ei.events
	return true
}
Retrieves the first page of events from the api. Returns false if there
was an error. It also sets the iterator object to the first page.
Use `.Err()` to retrieve the error.
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}
}
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,
	}
}
func (ei *EventIterator) Err() error {
	return ei.err
}
func (ei *EventIterator) Events() []Event {
	return ei.events
}
func (ei *EventIterator) GetFirstPage(opts GetEventsOptions) error {
	if opts.ForceAscending && opts.ForceDescending {
		return fmt.Errorf("collation cannot at once be both ascending and descending")
	}
	payload := newUrlEncodedPayload()
	if opts.Limit != 0 {
		payload.addValue("limit", fmt.Sprintf("%d", opts.Limit))
	}
	if opts.Compact {
		payload.addValue("pretty", "no")
	}
	if opts.ForceAscending {
		payload.addValue("ascending", "yes")
	}
	if opts.ForceDescending {
		payload.addValue("ascending", "no")
	}
	if opts.Begin != noTime {
		payload.addValue("begin", formatMailgunTime(&opts.Begin))
	}
	if opts.End != noTime {
		payload.addValue("end", formatMailgunTime(&opts.End))
	}
	if opts.Filter != nil {
		for k, v := range opts.Filter {
			payload.addValue(k, v)
		}
	}
	url, err := generateParameterizedUrl(ei.mg, eventsEndpoint, payload)
	if err != nil {
		return err
	}
	return ei.fetch(url)
}
func (ei *EventIterator) GetPrevious() error {
	return ei.fetch(ei.PrevURL)
}
func (ei *EventIterator) GetNext() error {
	return ei.fetch(ei.NextURL)
}
func (ei *EventIterator) Next(events *[]Event) bool {
	if ei.err != nil {
		return false
	}
	ei.err = ei.fetch(ei.NextURL)
	if ei.err != nil {
		return false
	}
	*events = ei.events
	if len(ei.events) == 0 {
		return false
	}
	return true
}