frostfs-node/pkg/services/object/search/v2/service.go
Evgenii Stratonikov 9ca20ad80f [#6] services/object: Remove pointer unneeded indirections
All `Service` are accessed by pointer.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-03-21 13:03:03 +03:00

58 lines
1.3 KiB
Go

package searchsvc
import (
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
searchsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search"
objutil "git.frostfs.info/TrueCloudLab/frostfs-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 {
var s Service
for i := range opts {
opts[i](&s.cfg)
}
return &s
}
// Search 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
}
}