[#263] Implement client for exchanging raw Protobuf messages

Implement generic `Client` that can communicate with the remote server via
protobuf `Message`'s. The client can uniformly execute any protobuf RPC
on the remote server using any of the supported transport protocols.
Currently only gRPC protocol is supported.

Additionally implement helpful functions to transmit messages by one of the
flow types: unary, client- or server-side stream.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-12 15:33:32 +03:00 committed by Alex Vanin
parent c61656a43f
commit 30c6ca0714
6 changed files with 364 additions and 0 deletions

29
rpc/client/client.go Normal file
View file

@ -0,0 +1,29 @@
package client
import (
"sync"
"github.com/nspcc-dev/neofs-api-go/rpc/grpc"
)
// Client represents client for exchanging messages
// with a remote server using Protobuf RPC.
type Client struct {
*cfg
gRPCClientOnce sync.Once
gRPCClient *grpc.Client
}
// New creates, configures via options and returns new Client instance.
func New(opts ...Option) *Client {
c := defaultCfg()
for _, opt := range opts {
opt(c)
}
return &Client{
cfg: c,
}
}