From abf9ad35730ecf2c11b83c5ed7bd9633a7ccfd20 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Sat, 26 Sep 2020 10:50:50 +0300 Subject: [PATCH] [#52] object/range: Attach received object header to result Signed-off-by: Leonard Lyubich --- pkg/services/object/range/res.go | 18 ++++++++++++++++++ pkg/services/object/range/service.go | 17 ++++++++++------- pkg/services/object/range/v2/service.go | 4 ++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/pkg/services/object/range/res.go b/pkg/services/object/range/res.go index fcdeb289d..90c3ccc41 100644 --- a/pkg/services/object/range/res.go +++ b/pkg/services/object/range/res.go @@ -1,5 +1,15 @@ package rangesvc +import ( + "github.com/nspcc-dev/neofs-node/pkg/core/object" +) + +type Result struct { + head *object.Object + + stream Streamer +} + type Response struct { chunk []byte } @@ -7,3 +17,11 @@ type Response struct { func (r *Response) PayloadChunk() []byte { return r.chunk } + +func (r *Result) Head() *object.Object { + return r.head +} + +func (r *Result) Stream() Streamer { + return r.stream +} diff --git a/pkg/services/object/range/service.go b/pkg/services/object/range/service.go index f9d2b8f9b..5ecbfec7c 100644 --- a/pkg/services/object/range/service.go +++ b/pkg/services/object/range/service.go @@ -55,7 +55,7 @@ func NewService(opts ...Option) *Service { } } -func (s *Service) GetRange(ctx context.Context, prm *Prm) (Streamer, error) { +func (s *Service) GetRange(ctx context.Context, prm *Prm) (*Result, error) { headResult, err := s.headSvc.Head(ctx, new(headsvc.Prm). WithAddress(prm.addr). OnlyLocal(prm.local), @@ -83,12 +83,15 @@ func (s *Service) GetRange(ctx context.Context, prm *Prm) (Streamer, error) { return nil, errors.Wrapf(err, "(%T) could not fill range traverser", s) } - return &streamer{ - cfg: s.cfg, - once: new(sync.Once), - ctx: ctx, - prm: prm, - rangeTraverser: rngTraverser, + return &Result{ + head: origin, + stream: &streamer{ + cfg: s.cfg, + once: new(sync.Once), + ctx: ctx, + prm: prm, + rangeTraverser: rngTraverser, + }, }, nil } diff --git a/pkg/services/object/range/v2/service.go b/pkg/services/object/range/v2/service.go index f7516cb8e..9c039e89c 100644 --- a/pkg/services/object/range/v2/service.go +++ b/pkg/services/object/range/v2/service.go @@ -35,12 +35,12 @@ func NewService(opts ...Option) *Service { // GetRange calls internal service and returns v2 object payload range stream. func (s *Service) GetRange(ctx context.Context, req *objectV2.GetRangeRequest) (objectV2.GetRangeObjectStreamer, error) { - stream, err := s.svc.GetRange(ctx, toPrm(req)) + r, err := s.svc.GetRange(ctx, toPrm(req)) if err != nil { return nil, errors.Wrapf(err, "(%T) could not get object payload range data", s) } - return fromResponse(stream), nil + return fromResponse(r.Stream()), nil } func WithInternalService(v *rangesvc.Service) Option {