-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathsearch.go
More file actions
42 lines (33 loc) · 1.31 KB
/
search.go
File metadata and controls
42 lines (33 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0
package client
import (
"context"
"fmt"
searchv1 "github.com/agntcy/dir/api/search/v1"
"github.com/agntcy/dir/client/streaming"
)
// SearchCIDs searches for record CIDs matching the given request.
func (c *Client) SearchCIDs(ctx context.Context, req *searchv1.SearchCIDsRequest) (streaming.StreamResult[searchv1.SearchCIDsResponse], error) {
stream, err := c.SearchServiceClient.SearchCIDs(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to create search CIDs stream: %w", err)
}
result, err := streaming.ProcessServerStream(ctx, stream)
if err != nil {
return nil, fmt.Errorf("failed to process search CIDs stream: %w", err)
}
return result, nil
}
// SearchRecords searches for full records matching the given request.
func (c *Client) SearchRecords(ctx context.Context, req *searchv1.SearchRecordsRequest) (streaming.StreamResult[searchv1.SearchRecordsResponse], error) {
stream, err := c.SearchServiceClient.SearchRecords(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to create search records stream: %w", err)
}
result, err := streaming.ProcessServerStream(ctx, stream)
if err != nil {
return nil, fmt.Errorf("failed to process search records stream: %w", err)
}
return result, nil
}