frostfs-node/pkg/services/object/put/v2/service.go
Leonard Lyubich 57f8d3745d [] service/object: Implement object Put distributed service
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-10-02 11:25:35 +03:00

52 lines
1,001 B
Go

package putsvc
import (
"context"
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
"github.com/pkg/errors"
)
// Service implements Put operation of Object service v2.
type Service struct {
*cfg
}
// Option represents Service constructor option.
type Option func(*cfg)
type cfg struct {
svc *putsvc.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,
}
}
// Put calls internal service and returns v2 object streamer.
func (s *Service) Put(ctx context.Context) (objectV2.PutObjectStreamer, error) {
stream, err := s.svc.Put(ctx)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not open object put stream", s)
}
return &streamer{
stream: stream,
}, nil
}
func WithInternalService(v *putsvc.Service) Option {
return func(c *cfg) {
c.svc = v
}
}