Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:36
Show Gist options
  • Save percybolmer/d010f0ebbaf17566635dab2282c30c56 to your computer and use it in GitHub Desktop.
Save percybolmer/d010f0ebbaf17566635dab2282c30c56 to your computer and use it in GitHub Desktop.
An Example of a unary client interceptor
// ClientPingCounter is a UnaryClientInterceptor that will count the number of API calls on the Client side
func (pc *PingCounter) ClientPingCounter(ctx context.Context, method string, req interface{}, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
pc.Pings++
// Run regular gRPC call after
// If you dont run the invoker, the gRPC call wont be sent to the server
return invoker(ctx, method, req, reply, cc, opts...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment