Last active
August 6, 2021 11:36
-
-
Save percybolmer/d010f0ebbaf17566635dab2282c30c56 to your computer and use it in GitHub Desktop.
An Example of a unary client interceptor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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