func writeEvents(client *goes.Client, streamName string) {
	existingEvents := createTestEvents(10, streamName, serverURL, "FooEvent")
	writer := client.NewStreamWriter(streamName)
	err := writer.Append(nil, existingEvents...)
	if err != nil {
		log.Fatal(err)
	}
	ticker := time.NewTicker(time.Second * 2)
	go func() {
		for _ = range ticker.C {
			num := rand.Intn(5)
			newEvents := createTestEvents(num, streamName, serverURL, "FooEvent")
			writer.Append(nil, newEvents...)
		}
	}()
}
writeEvents will create an initial set of events and then write them to
the eventstore.
At two second intervals a random number of events between 1 and 5 will be written
to the eventstore.
package main
import (
	"encoding/json"
	"fmt"
	"log"
	"math/rand"
	"net/url"
	"time"
	"github.com/jetbasrawi/go.geteventstore"
)
var (
	serverURL = "http://localhost:2113"
)
type FooEvent struct {
	Foo string `json:"foo"`
}
type FooMeta struct {
	Bar string `json:"bar"`
}
func main() {
	client, err := goes.NewClient(nil, serverURL)
	if err != nil {
		log.Fatal(err)
	}
	client.SetBasicAuth("admin", "changeit")
	streamName := "longpollstream"
	writeEvents(client, streamName)
	log.Printf("\nReading events from the eventstore\n")
	reader := client.NewStreamReader(streamName)
	for reader.Next() {
		if reader.Err() != nil {
			switch err := reader.Err().(type) {
			case *url.Error, *goes.ErrTemporarilyUnavailable:
				log.Println("The server is not ready. Will retry after 30 seconds.")
				<-time.After(time.Duration(30) * time.Second)
			case *goes.ErrNotFound:
				<-time.After(time.Duration(10) * time.Second)
			case *goes.ErrUnauthorized:
				log.Fatal(err)
			case *goes.ErrNoMoreEvents:
				log.Println("No more events. Will poll head of stream.")
				reader.LongPoll(15)
			default:
				log.Fatal(err)
			}
		} else {
			event := FooEvent{}
			meta := FooMeta{}
			if err := reader.Scan(&event, &meta); err != nil {
				log.Fatal(err)
			}
			log.Printf("\n Event %d returned %#v\n Meta returned %#v\n\n", reader.EventResponse().Event.EventNumber, event, meta)
		}
	}
}