[#444] reputation/grpc: Implement gRPC ReputationServiceServer

Implement gRPC ReputationServiceServer on structure that forwards requests
to underlying NeoFS API v2 ReputationService `Server`.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-24 12:54:19 +03:00 committed by Alex Vanin
parent df97e35f30
commit b37b608150

View file

@ -0,0 +1,37 @@
package grpcreputation
import (
"context"
"github.com/nspcc-dev/neofs-api-go/v2/reputation"
reputation2 "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc"
)
// Server wraps NeoFS API v2 Container service server
// and provides gRPC Container service server interface.
type Server struct {
srv reputationrpc.Server
}
// New creates, initializes and returns Server instance.
func New(srv reputationrpc.Server) *Server {
return &Server{
srv: srv,
}
}
func (s *Server) SendLocalTrust(ctx context.Context, r *reputation2.SendLocalTrustRequest) (*reputation2.SendLocalTrustResponse, error) {
req := new(reputation.SendLocalTrustRequest)
if err := req.FromGRPCMessage(r); err != nil {
return nil, err
}
resp, err := s.srv.SendLocalTrust(ctx, req)
if err != nil {
// TODO: think about how we transport errors through gRPC
return nil, err
}
return resp.ToGRPCMessage().(*reputation2.SendLocalTrustResponse), nil
}