@@ -120,25 +120,37 @@ type BulkStateItem struct {
120120type SetStateItem struct {
121121 Key string
122122 Value []byte
123- Etag string
123+ Etag * ETag
124124 Metadata map [string ]string
125125 Options * StateOptions
126126}
127127
128+ // ETag represents an versioned record information
129+ type ETag struct {
130+ Value string
131+ }
132+
128133// StateOptions represents the state store persistence policy.
129134type StateOptions struct {
130135 Concurrency StateConcurrency
131136 Consistency StateConsistency
132137}
133138
134139func toProtoSaveStateItem (si * SetStateItem ) (item * v1.StateItem ) {
135- return & v1.StateItem {
136- Etag : si .Etag ,
140+ s := & v1.StateItem {
137141 Key : si .Key ,
138142 Metadata : si .Metadata ,
139143 Value : si .Value ,
140144 Options : toProtoStateOptions (si .Options ),
141145 }
146+
147+ if si .Etag != nil {
148+ s .Etag = & v1.Etag {
149+ Value : si .Etag .Value ,
150+ }
151+ }
152+
153+ return s
142154}
143155
144156func toProtoStateOptions (so * StateOptions ) (opts * v1.StateOptions ) {
@@ -288,32 +300,37 @@ func (c *GRPCClient) GetStateWithConsistency(ctx context.Context, storeName, key
288300 }
289301
290302 return & StateItem {
291- Etag : result .Etag ,
292- Key : key ,
293- Value : result .Data ,
303+ Etag : result .Etag ,
304+ Key : key ,
305+ Value : result .Data ,
294306 Metadata : result .Metadata ,
295307 }, nil
296308}
297309
298310// DeleteState deletes content from store using default state options.
299311func (c * GRPCClient ) DeleteState (ctx context.Context , storeName , key string ) error {
300- return c .DeleteStateWithETag (ctx , storeName , key , "" , nil , nil )
312+ return c .DeleteStateWithETag (ctx , storeName , key , nil , nil , nil )
301313}
302314
303315// DeleteStateWithETag deletes content from store using provided state options and etag.
304- func (c * GRPCClient ) DeleteStateWithETag (ctx context.Context , storeName , key , etag string , meta map [string ]string , opts * StateOptions ) error {
316+ func (c * GRPCClient ) DeleteStateWithETag (ctx context.Context , storeName , key string , etag * ETag , meta map [string ]string , opts * StateOptions ) error {
305317 if err := hasRequiredStateArgs (storeName , key ); err != nil {
306318 return errors .Wrap (err , "missing required arguments" )
307319 }
308320
309321 req := & pb.DeleteStateRequest {
310322 StoreName : storeName ,
311323 Key : key ,
312- Etag : etag ,
313324 Options : toProtoStateOptions (opts ),
314325 Metadata : meta ,
315326 }
316327
328+ if etag != nil {
329+ req .Etag = & v1.Etag {
330+ Value : etag .Value ,
331+ }
332+ }
333+
317334 _ , err := c .protoClient .DeleteState (c .withAuthToken (ctx ), req )
318335 if err != nil {
319336 return errors .Wrap (err , "error deleting state" )
0 commit comments