Skip to content

Latest commit

 

History

History
84 lines (75 loc) · 2.5 KB

README.md

File metadata and controls

84 lines (75 loc) · 2.5 KB

GOES is an Event Store golang TCP Library for Go.

Build Status GoDoc Coverage Status Go Report Card

Example

Create a configuration that will be used to describe how to connect to Event Store

//connect to a single node
config := &goes.Configuration{
    ReconnectionDelay:   10000,
    MaxReconnects:       10,
    MaxOperationRetries: 10,
    Address:             "127.0.0.1",
    Port:                1113,
    Login:               "admin",
    Password:            "changeit",
}

//or a cluster via gossip seeds
config := &goes.Configuration{
    ReconnectionDelay:   10000,
    MaxReconnects:       10,
    MaxOperationRetries: 10,
    Login:               "admin",
    Password:            "changeit",
    EndpointDiscoverer:  discoverer = goes.GossipEndpointDiscoverer{
        MaxDiscoverAttempts: 10,
        GossipSeeds:         []string{"http://127.0.0.1:2113", "http://127.0.0.1:1113"},
    }
}

Connect to Event Store

conn, err := goes.NewEventStoreConnection(config)
if err != nil {
	log.Fatalf("[fatal] %s", err.Error())
}
err = conn.Connect()
defer conn.Close()
if err != nil {
	log.Fatalf("[fatal] %s", err.Error())
}

Write events to Event Store

events := []goes.Event{
	goes.Event{
		EventID:   uuid.NewV4(),
		EventType: "itemAdded",
		IsJSON:    true,
		Data:      []byte("{\"price\": \"100\"}"),
		Metadata:  []byte("metadata"),
	},
	goes.Event{
		EventID:   uuid.NewV4(),
		EventType: "itemAdded",
		IsJSON:    true,
		Data:      []byte("{\"price\": \"120\"}"),
		Metadata:  []byte("metadata"),
	},
}

result, err := goes.AppendToStream(conn, "shoppingCart-1", -2, events)
if *result.Result != protobuf.OperationResult_Success {
	log.Printf("[info] WriteEvents failed. %v", result.Result.String())
}
if err != nil {
	log.Printf("[error] WriteEvents failed. %v", err.Error())
}

Reading from Event Store

goes.ReadSingleEvent(conn, "$stats-127.0.0.1:2113", 0, true, true)

LICENSE

Licenced under MIT.