Skip to content

Commit

Permalink
change client example
Browse files Browse the repository at this point in the history
  • Loading branch information
vadiminshakov committed Oct 1, 2023
1 parent f649a81 commit 4e1d920
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions examples/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"github.com/vadiminshakov/committer/io/gateway/grpc/client"
pb "github.com/vadiminshakov/committer/io/gateway/grpc/proto"
"github.com/vadiminshakov/committer/io/trace"
"strconv"
)

const coordinatorAddr = "localhost:3000"

func main() {
key, value := "somekey", []byte("somevalue")
key, value := "somekey", "somevalue"
tracer, err := trace.Tracer("client", coordinatorAddr)
if err != nil {
panic(err)
Expand All @@ -23,19 +24,21 @@ func main() {
panic(err)
}

// put a key-value pair
resp, err := cli.Put(context.Background(), key, value)
if err != nil {
panic(err)
}
if resp.Type != pb.Type_ACK {
panic("msg is not acknowledged")
}
for i := 0; i < 5; i++ {
// put a key-value pair
resp, err := cli.Put(context.Background(), key+strconv.Itoa(i), []byte(value+strconv.Itoa(i)))
if err != nil {
panic(err)
}
if resp.Type != pb.Type_ACK {
panic("msg is not acknowledged")
}

// read committed key
v, err := cli.Get(context.Background(), key)
if err != nil {
panic(err)
// read committed key
v, err := cli.Get(context.Background(), key+strconv.Itoa(i))
if err != nil {
panic(err)
}
fmt.Printf("got value for key '%s': %s", key+strconv.Itoa(i), string(v.Value)+strconv.Itoa(i))
}
fmt.Printf("got value for key '%s': %s", key, v.Value)
}

0 comments on commit 4e1d920

Please sign in to comment.