frostfs-node/pkg/services/object/get/service.go
Leonard Lyubich bf2c33d7a9 [#52] services/object: Implement Get service
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-10-02 11:25:36 +03:00

55 lines
835 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().
OnlyLocal(prm.local),
)
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
}
}