Skip to content

Instantly share code, notes, and snippets.

@harunpeksen
Created March 10, 2022 16:11
Show Gist options
  • Save harunpeksen/4d1e388381677d9aad4501e65651ad8d to your computer and use it in GitHub Desktop.
Save harunpeksen/4d1e388381677d9aad4501e65651ad8d to your computer and use it in GitHub Desktop.
// Example of Unary Interceptor
func exampleUnaryServerInterceptor(ctx context.Context, req interface{},
info *grpc.UnaryServerInfo, handler grpc.UnaryHandler)
(interface{}, error) {
// Codes before executing GRPC
log.Println("Some messages before execution")
// Usual execution of a unary RPC
m, err := handler(ctx, req)
// Codes after executing GRPC
log.Println("Some messages after execution")
return m, err
}
func main() {
...
// Registering gRPC server with UnaryInterceptor
s := grpc.NewServer(grpc.UnaryInterceptor(exampleUnaryServerInterceptor))
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment