[#294] searchsvcv2: Refactor service constructor

Pass required deps as args.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-07-06 12:56:45 +03:00 committed by Evgenii Stratonikov
parent e8091101c7
commit c83e7c875f
2 changed files with 5 additions and 36 deletions

View file

@ -346,10 +346,7 @@ func createSearchSvc(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.Trav
} }
func createSearchSvcV2(sSearch *searchsvc.Service, keyStorage *util.KeyStorage) *searchsvcV2.Service { func createSearchSvcV2(sSearch *searchsvc.Service, keyStorage *util.KeyStorage) *searchsvcV2.Service {
return searchsvcV2.NewService( return searchsvcV2.NewService(sSearch, keyStorage)
searchsvcV2.WithInternalService(sSearch),
searchsvcV2.WithKeyStorage(keyStorage),
)
} }
func createGetService(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.TraverserGenerator, func createGetService(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.TraverserGenerator,

View file

@ -9,28 +9,15 @@ import (
// Service implements Search operation of Object service v2. // Service implements Search operation of Object service v2.
type Service struct { type Service struct {
*cfg
}
// Option represents Service constructor option.
type Option func(*cfg)
type cfg struct {
svc *searchsvc.Service svc *searchsvc.Service
keyStorage *objutil.KeyStorage keyStorage *objutil.KeyStorage
} }
// NewService constructs Service instance from provided options. // NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service { func NewService(s *searchsvc.Service, ks *objutil.KeyStorage) *Service {
c := new(cfg)
for i := range opts {
opts[i](c)
}
return &Service{ return &Service{
cfg: c, svc: s,
keyStorage: ks,
} }
} }
@ -43,18 +30,3 @@ func (s *Service) Search(req *objectV2.SearchRequest, stream objectSvc.SearchStr
return s.svc.Search(stream.Context(), *p) 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
}
}