frostfs-node/pkg/services/object/head/v2/service.go
Leonard Lyubich 05f3963975 [#38] service/object: Implement simplified object Head service
Implement Head service w/o linking object processing and restoration from
split-chain.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-10-02 11:25:35 +03:00

50 lines
1 KiB
Go

package headsvc
import (
"context"
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head"
"github.com/pkg/errors"
)
// Service implements Head operation of Object service v2.
type Service struct {
*cfg
}
// Option represents Service constructor option.
type Option func(*cfg)
type cfg struct {
svc *headsvc.Service
}
// NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service {
c := new(cfg)
for i := range opts {
opts[i](c)
}
return &Service{
cfg: c,
}
}
// Head calls internal service and returns v2 object header.
func (s *Service) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV2.HeadResponse, error) {
r, err := s.svc.Head(ctx, toPrm(req))
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not get object header", s)
}
return fromResponse(r, req.GetBody().GetMainOnly()), nil
}
func WithInternalService(v *headsvc.Service) Option {
return func(c *cfg) {
c.svc = v
}
}