[#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:
parent
c61656a43f
commit
30c6ca0714
6 changed files with 364 additions and 0 deletions
41
rpc/client/connect.go
Normal file
41
rpc/client/connect.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/rpc/grpc"
|
||||
grpcstd "google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func (c *Client) createGRPCClient() (err error) {
|
||||
c.gRPCClientOnce.Do(func() {
|
||||
if err = c.openGRPCConn(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.gRPCClient = grpc.New(grpc.WithClientConnection(c.conn))
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var errInvalidEndpoint = errors.New("invalid endpoint options")
|
||||
|
||||
func (c *Client) openGRPCConn() error {
|
||||
if c.conn != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if c.addr == "" {
|
||||
return errInvalidEndpoint
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
dialCtx, cancel := context.WithTimeout(context.Background(), c.dialTimeout)
|
||||
c.conn, err = grpcstd.DialContext(dialCtx, c.addr, grpcstd.WithInsecure())
|
||||
cancel()
|
||||
|
||||
return err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue