GRPC Programming Model: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * gRPC =Instantiate a GRPC Client=")
 
 
(9 intermediate revisions by the same user not shown)
Line 3: Line 3:


=Instantiate a GRPC Client=
=Instantiate a GRPC Client=
=A Client Invocation=
The generated typed client contains a <code>cc</code> reference to <code>google.golang.org/grpc</code> <code>ClientConn</code> instance, which implements <code>ClientConnInterface</code>.
When a typed invocation is made, <code>cc</code> is invoked as such:
<syntaxhighlight lang='go'>
cc.Invoke(ctx, "/blue.service.quota.v1.QuotaService/SomeMethod", in, out, opts)
</syntaxhighlight>
[[GRPC_Concepts#Dial_Options|Dial Options]].
=Error Handling=
https://grpc.io/docs/guides/error/
https://cloud.google.com/apis/design/errors#error_model
https://grpc.io/docs/guides/status-codes/
Use https://pkg.go.dev/google.golang.org/grpc/internal/status
gRPC service handlers should return error created by the <code>status</code> package, and gRPC clients should expect a corresponding error to be returned from the RPC call.
<syntaxhighlight lang='go'>
status.Errorf(codes.InvalidArgument, "request missing required field: Name")
</syntaxhighlight>
https://grpc.github.io/grpc/core/md_doc_statuscodes.html?ref=apisyouwonthate.com
Converting a general error to a known status, if possible:
<syntaxhighlight lang='go'>
status.FromError()
</syntaxhighlight>

Latest revision as of 20:53, 20 August 2024

Internal

Instantiate a GRPC Client

A Client Invocation

The generated typed client contains a cc reference to google.golang.org/grpc ClientConn instance, which implements ClientConnInterface.

When a typed invocation is made, cc is invoked as such:

cc.Invoke(ctx, "/blue.service.quota.v1.QuotaService/SomeMethod", in, out, opts)

Dial Options.

Error Handling

https://grpc.io/docs/guides/error/

https://cloud.google.com/apis/design/errors#error_model

https://grpc.io/docs/guides/status-codes/

Use https://pkg.go.dev/google.golang.org/grpc/internal/status

gRPC service handlers should return error created by the status package, and gRPC clients should expect a corresponding error to be returned from the RPC call.

status.Errorf(codes.InvalidArgument, "request missing required field: Name")

https://grpc.github.io/grpc/core/md_doc_statuscodes.html?ref=apisyouwonthate.com


Converting a general error to a known status, if possible:

status.FromError()