etag output on get state

This commit is contained in:
Mark Chmarny 2020-06-16 17:37:20 -07:00
parent 0f19d63ca0
commit fee04fad27
3 changed files with 9 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import (
)
// InvokeBinding invokes specific operation on the configured Dapr binding
// This method covers both the input, output, and bi-directional bindings
func (c *Client) InvokeBinding(ctx context.Context, name, op string, in []byte, min map[string]string) (out []byte, mout map[string]string, err error) {
if name == "" {
return nil, nil, errors.New("nil topic")

View File

@ -248,12 +248,12 @@ func (c *Client) SaveStateJSON(ctx context.Context, store, key string, in interf
// *** Get State ***
// GetStateWithConsistency retreaves state from specific store using provided request
func (c *Client) GetStateWithConsistency(ctx context.Context, store, key string, sc StateConsistency) (out []byte, err error) {
func (c *Client) GetStateWithConsistency(ctx context.Context, store, key string, sc StateConsistency) (out []byte, etag string, err error) {
if store == "" {
return nil, errors.New("nil store")
return nil, "", errors.New("nil store")
}
if key == "" {
return nil, errors.New("nil key")
return nil, "", errors.New("nil key")
}
req := &pb.GetStateRequest{
@ -264,14 +264,14 @@ func (c *Client) GetStateWithConsistency(ctx context.Context, store, key string,
result, err := c.protoClient.GetState(authContext(ctx), req)
if err != nil {
return nil, errors.Wrap(err, "error getting state")
return nil, "", errors.Wrap(err, "error getting state")
}
return result.Data, nil
return result.Data, result.Etag, nil
}
// GetState retreaves state from specific store using default consistency option
func (c *Client) GetState(ctx context.Context, store, key string) (out []byte, err error) {
func (c *Client) GetState(ctx context.Context, store, key string) (out []byte, etag string, err error) {
return c.GetStateWithConsistency(ctx, store, key, StateConsistencyStrong)
}

View File

@ -39,11 +39,11 @@ func main() {
logger.Println("data saved")
// get state for key key1
dataOut, err := client.GetState(ctx, "statestore", "key1")
dataOut, etag, err := client.GetState(ctx, "statestore", "key1")
if err != nil {
logger.Panic(err)
}
logger.Printf("data out: %s", string(dataOut))
logger.Printf("data out [etag:%s]: %s", etag, string(dataOut))
// delete state for key key1
err = client.DeleteState(ctx, "statestore", "key1")