Skip to content

Instantly share code, notes, and snippets.

@harunpeksen
Created March 11, 2022 15:45
Show Gist options
  • Save harunpeksen/2112bb048956a45e6974adc8fabd2b64 to your computer and use it in GitHub Desktop.
Save harunpeksen/2112bb048956a45e6974adc8fabd2b64 to your computer and use it in GitHub Desktop.
func exampleUnaryClientInterceptor(ctx context.Context, method string, req, reply interface{},
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
// Codes before executing GRPC
log.Println("Some messages before execution")
// usual invocation of the remote method
err := invoker(ctx, method, req, reply, cc, opts...)
// Codes after executing GRPC
log.Println("Some messages after execution")
return err
}
func main() {
...
// Setting up a gRPC connection
conn, err := grpc.Dial(address, grpc.WithInsecure(),grpc.WithUnaryInterceptor(exampleUnaryClientInterceptor))
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment