Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrMethodNotFound = status.Error(codes.Unimplemented, "method not found")
View Source
var ErrMethodShape = status.Error(codes.Internal, "method stream shape mismatch")
Functions ¶
func ServerToClient ¶
func ServerToClient(desc grpc.ServiceDesc, srv any) grpc.ClientConnInterface
ServerToClient returns a grpc.ClientConnInterface that can service all methods described by desc. srv is the gRPC server implementation type (a type that could be passed to a grpc RegisterXxxServer function).
Unary and streaming calls are supported.
The call options grpc.Header and grpc.Trailer are supported for unary RPCs. All other call options are ignored.
Example ¶
package main import ( "context" "fmt" "github.com/smart-core-os/sc-golang/internal/testproto" ) // Given the following gRPC service definition: // // syntax = "proto3"; // service TestApi { // rpc Unary(UnaryRequest) returns (UnaryResponse); // } // message UnaryRequest { // string msg = 1; // } // message UnaryResponse { // string msg = 1; // } func main() { srv := &exampleServer{} conn := ServerToClient(testproto.TestApi_ServiceDesc, srv) client := testproto.NewTestApiClient(conn) res, err := client.Unary(context.Background(), &testproto.UnaryRequest{Msg: "hello"}) if err != nil { panic(err) } fmt.Println(res.Msg) } type exampleServer struct { testproto.UnimplementedTestApiServer } func (s *exampleServer) Unary(ctx context.Context, req *testproto.UnaryRequest) (*testproto.UnaryResponse, error) { return &testproto.UnaryResponse{Msg: req.Msg}, nil }
Output: hello
func UnwrapFully ¶
UnwrapFully repeatedly casts then unwraps obj until obj no longer implements Unwrapper.
Types ¶
type ClientServerStream ¶
type ClientServerStream struct {
// contains filtered or unexported fields
}
ClientServerStream combines both a grpc.ServerStream and grpc.ClientStream
func NewClientServerStream ¶
func NewClientServerStream(ctx context.Context) *ClientServerStream
func (*ClientServerStream) Client ¶
func (s *ClientServerStream) Client() grpc.ClientStream
func (*ClientServerStream) Close ¶
func (s *ClientServerStream) Close(err error)
func (*ClientServerStream) Server ¶
func (s *ClientServerStream) Server() grpc.ServerStream
type ServiceUnwrapper ¶
type ServiceUnwrapper interface {
UnwrapService() (grpc.ClientConnInterface, grpc.ServiceDesc)
}
Click to show internal directories.
Click to hide internal directories.