-
Notifications
You must be signed in to change notification settings - Fork 38
/
service.go
60 lines (48 loc) · 1.32 KB
/
service.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package searchsvc
import (
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
)
// Service implements Search operation of Object service v2.
type Service struct {
*cfg
}
// Option represents Service constructor option.
type Option func(*cfg)
type cfg struct {
svc *searchsvc.Service
keyStorage *objutil.KeyStorage
}
// NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service {
c := new(cfg)
for i := range opts {
opts[i](c)
}
return &Service{
cfg: c,
}
}
// Get calls internal service and returns v2 object stream.
func (s *Service) Search(req *objectV2.SearchRequest, stream objectSvc.SearchStream) error {
p, err := s.toPrm(req, stream)
if err != nil {
return err
}
return s.svc.Search(stream.Context(), *p)
}
// WithInternalService returns option to set entity
// that handles request payload.
func WithInternalService(v *searchsvc.Service) Option {
return func(c *cfg) {
c.svc = v
}
}
// WithKeyStorage returns option to set local private key storage.
func WithKeyStorage(ks *objutil.KeyStorage) Option {
return func(c *cfg) {
c.keyStorage = ks
}
}