goes

command module
v0.0.0-...-cba03c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 5 Imported by: 0

README

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL