mirror of https://github.com/dapr/go-sdk.git
				
				
				
			etag output on get state
This commit is contained in:
		
							parent
							
								
									0f19d63ca0
								
							
						
					
					
						commit
						fee04fad27
					
				| 
						 | 
					@ -9,6 +9,7 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// InvokeBinding invokes specific operation on the configured Dapr binding
 | 
					// 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) {
 | 
					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 == "" {
 | 
						if name == "" {
 | 
				
			||||||
		return nil, nil, errors.New("nil topic")
 | 
							return nil, nil, errors.New("nil topic")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -248,12 +248,12 @@ func (c *Client) SaveStateJSON(ctx context.Context, store, key string, in interf
 | 
				
			||||||
// *** Get State ***
 | 
					// *** Get State ***
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// GetStateWithConsistency retreaves state from specific store using provided request
 | 
					// 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 == "" {
 | 
						if store == "" {
 | 
				
			||||||
		return nil, errors.New("nil store")
 | 
							return nil, "", errors.New("nil store")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if key == "" {
 | 
						if key == "" {
 | 
				
			||||||
		return nil, errors.New("nil key")
 | 
							return nil, "", errors.New("nil key")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	req := &pb.GetStateRequest{
 | 
						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)
 | 
						result, err := c.protoClient.GetState(authContext(ctx), req)
 | 
				
			||||||
	if err != nil {
 | 
						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
 | 
					// 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)
 | 
						return c.GetStateWithConsistency(ctx, store, key, StateConsistencyStrong)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,11 +39,11 @@ func main() {
 | 
				
			||||||
	logger.Println("data saved")
 | 
						logger.Println("data saved")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// get state for key key1
 | 
						// get state for key key1
 | 
				
			||||||
	dataOut, err := client.GetState(ctx, "statestore", "key1")
 | 
						dataOut, etag, err := client.GetState(ctx, "statestore", "key1")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Panic(err)
 | 
							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
 | 
						// delete state for key key1
 | 
				
			||||||
	err = client.DeleteState(ctx, "statestore", "key1")
 | 
						err = client.DeleteState(ctx, "statestore", "key1")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue