forked from TrueCloudLab/frostfs-node
[#294] searchsvcv2: Refactor service constructor
Pass required deps as args. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>logs-linter
parent
e8091101c7
commit
c83e7c875f
|
@ -346,10 +346,7 @@ func createSearchSvc(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.Trav
|
|||
}
|
||||
|
||||
func createSearchSvcV2(sSearch *searchsvc.Service, keyStorage *util.KeyStorage) *searchsvcV2.Service {
|
||||
return searchsvcV2.NewService(
|
||||
searchsvcV2.WithInternalService(sSearch),
|
||||
searchsvcV2.WithKeyStorage(keyStorage),
|
||||
)
|
||||
return searchsvcV2.NewService(sSearch, keyStorage)
|
||||
}
|
||||
|
||||
func createGetService(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.TraverserGenerator,
|
||||
|
|
|
@ -9,28 +9,15 @@ import (
|
|||
|
||||
// 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)
|
||||
}
|
||||
|
||||
func NewService(s *searchsvc.Service, ks *objutil.KeyStorage) *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)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue