31

GitHub - vectorhacker/goro: Go client library for EventStore.

 6 years ago
source link: https://github.com/vectorhacker/goro
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Goro is a Go client library for Event Store.

Godoc

Example:

package main

import (
    "bytes"
    "context"
    "encoding/json"
    "fmt"
    
    "github.com/vectorhacker/goro"
)

func main() {
    // create a client to use the Event Store
    client := goro.Connect("http://localhost:2113", goro.WithBasicAuth("admin", "changeit"))


    writer := client.Writer("messages")
    reader := client.FowardsReader("messages")
    catchupSubscription := client.CatchupSubscription("messages", 0) // start from 0

    data := []byte("{\"message\": \"hello world\"}")

    // write the event
    ctx := context.Background()
    event := goro.CreateEvent(
        "message",
        data,
        nil, // nil metadata
        0,
    )
    err = writer.Write(ctx, goro.ExpectedVersionAny, event)
    if err != nil {
        panic(err)
    }

    // subscribe to a stream of events
    go func() {
        ctx := context.Background()
        messages := catchupSubscription.Subscribe(ctx)

        for message := range messages {
            fmt.Printf("%s\n", messages.Event.Data)
        }
    }()

    // read events
    events, err := reader.Read(ctx, 0, 1)
    if err != nil {
        panic(err)
    }

    for _, event := range events {
        fmt.Printf("%s\n", event.Data)
    }
}
  • Tests
  • Competing Consumers
  • Projections
  • Read Events
  • Stream Events
  • Write Events
  • User Management

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK