frostfs-node/pkg/network/transport/session/grpc/service.go
Leonard Lyubich 718a2fad26 [#425] services: Define service interfaces that was removed from API lib
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-17 15:00:37 +03:00

33 lines
931 B
Go

package session
import (
"context"
"github.com/nspcc-dev/neofs-api-go/v2/session"
sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
sessionsvc "github.com/nspcc-dev/neofs-node/pkg/services/session"
)
// Server wraps NeoFS API Session service and
// provides gRPC Session service server interface.
type Server struct {
srv sessionsvc.Server
}
// New creates, initializes and returns Server instance.
func New(c sessionsvc.Server) *Server {
return &Server{
srv: c,
}
}
// Create converts gRPC CreateRequest message and passes it to internal Session service.
func (s *Server) Create(ctx context.Context, req *sessionGRPC.CreateRequest) (*sessionGRPC.CreateResponse, error) {
resp, err := s.srv.Create(ctx, session.CreateRequestFromGRPCMessage(req))
if err != nil {
// TODO: think about how we transport errors through gRPC
return nil, err
}
return session.CreateResponseToGRPCMessage(resp), nil
}