frostfs-node/pkg/services/object/get/service.go
Leonard Lyubich 39c17253be [#57] services/object: Combine common service parameters
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-10-02 11:25:36 +03:00

55 lines
840 B
Go

package getsvc
import (
"context"
rangesvc "github.com/nspcc-dev/neofs-node/pkg/services/object/range"
"github.com/pkg/errors"
)
type Service struct {
*cfg
}
type Option func(*cfg)
type cfg struct {
rngSvc *rangesvc.Service
}
func defaultCfg() *cfg {
return new(cfg)
}
func NewService(opts ...Option) *Service {
c := defaultCfg()
for i := range opts {
opts[i](c)
}
return &Service{
cfg: c,
}
}
func (s *Service) Get(ctx context.Context, prm *Prm) (*Streamer, error) {
r, err := s.rngSvc.GetRange(ctx, new(rangesvc.Prm).
WithAddress(prm.addr).
FullRange().
WithCommonPrm(prm.common),
)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not get range", s)
}
return &Streamer{
rngRes: r,
}, nil
}
func WithRangeService(v *rangesvc.Service) Option {
return func(c *cfg) {
c.rngSvc = v
}
}