@@ -18,6 +18,7 @@ import (
18
18
"context"
19
19
"encoding/base64"
20
20
"errors"
21
+
21
22
"github.com/atomix/api/proto/atomix/headers"
22
23
api "github.com/atomix/api/proto/atomix/list"
23
24
"github.com/atomix/go-client/pkg/client/primitive"
@@ -58,6 +59,9 @@ type List interface {
58
59
// Len gets the length of the list
59
60
Len (ctx context.Context ) (int , error )
60
61
62
+ // Contains checks whether the list contains a value
63
+ Contains (ctx context.Context , value []byte ) (bool , error )
64
+
61
65
// Slice returns a slice of the list from the given start index to the given end index
62
66
Slice (ctx context.Context , from int , to int ) (List , error )
63
67
@@ -258,6 +262,25 @@ func (l *list) Remove(ctx context.Context, index int) ([]byte, error) {
258
262
}
259
263
}
260
264
265
+ func (l * list ) Contains (ctx context.Context , value []byte ) (bool , error ) {
266
+ response , err := l .instance .DoQuery (ctx , func (ctx context.Context , conn * grpc.ClientConn , header * headers.RequestHeader ) (* headers.ResponseHeader , interface {}, error ) {
267
+ client := api .NewListServiceClient (conn )
268
+ request := & api.ContainsRequest {
269
+ Header : header ,
270
+ Value : base64 .StdEncoding .EncodeToString (value ),
271
+ }
272
+ response , err := client .Contains (ctx , request )
273
+ if err != nil {
274
+ return nil , nil , err
275
+ }
276
+ return response .Header , response , nil
277
+ })
278
+ if err != nil {
279
+ return false , err
280
+ }
281
+ return bool (response .(* api.ContainsResponse ).Contains ), nil
282
+ }
283
+
261
284
func (l * list ) Len (ctx context.Context ) (int , error ) {
262
285
response , err := l .instance .DoQuery (ctx , func (ctx context.Context , conn * grpc.ClientConn , header * headers.RequestHeader ) (* headers.ResponseHeader , interface {}, error ) {
263
286
client := api .NewListServiceClient (conn )
0 commit comments