[#263] Implement client for exchanging raw messages using gRPC protocol

Implement gRPC client that can uniformly execute any RPC on the remote
server. In the primary implementation, the client is a thin wrapper over
gRPC client connection that is required to create the client. In the future,
it is planned to expand the library with convenient functionality.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-12 14:17:16 +03:00 committed by Alex Vanin
parent ae2fb263f1
commit cf765a61a6
7 changed files with 271 additions and 0 deletions

75
rpc/common/call.go Normal file
View file

@ -0,0 +1,75 @@
package common
type callType uint8
const (
_ callType = iota
callUnary
callClientStream
callServerStream
callBidirStream
)
// CallMethodInfo is an information about the RPC.
type CallMethodInfo struct {
// Name of the service.
Service string
// Name of the RPC.
Name string
t callType
}
// ServerStream checks if CallMethodInfo contains
// information about the server-side streaming RPC.
func (c CallMethodInfo) ServerStream() bool {
return c.t == callServerStream || c.t == callBidirStream
}
// ClientStream checks if CallMethodInfo contains
// information about the client-side streaming RPC.
func (c CallMethodInfo) ClientStream() bool {
return c.t == callClientStream || c.t == callBidirStream
}
func (c *CallMethodInfo) setCommon(service, name string) {
c.Service = service
c.Name = name
}
// CallMethodInfoUnary returns CallMethodInfo structure
// initialized for the unary RPC.
func CallMethodInfoUnary(service, name string) (info CallMethodInfo) {
info.setCommon(service, name)
info.t = callUnary
return
}
// CallMethodInfoClientStream returns CallMethodInfo structure
// initialized for the client-side streaming RPC.
func CallMethodInfoClientStream(service, name string) (info CallMethodInfo) {
info.setCommon(service, name)
info.t = callClientStream
return
}
// CallMethodInfoServerStream returns CallMethodInfo structure
// initialized for the server-side streaming RPC.
func CallMethodInfoServerStream(service, name string) (info CallMethodInfo) {
info.setCommon(service, name)
info.t = callServerStream
return
}
// CallMethodInfoBidirectionalStream returns CallMethodInfo structure
// initialized for the bidirectional streaming RPC.
func CallMethodInfoBidirectionalStream(service, name string) (info CallMethodInfo) {
info.setCommon(service, name)
info.t = callBidirStream
return
}