Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:36
Show Gist options
  • Save percybolmer/47f5c12d99e7c18efe3d2ba760a7535f to your computer and use it in GitHub Desktop.
Save percybolmer/47f5c12d99e7c18efe3d2ba760a7535f to your computer and use it in GitHub Desktop.
package interceptors
import (
"context"
"fmt"
"google.golang.org/grpc"
)
// LogRequest is a gRPC UnaryServerInterceptor that will log the API call to stdOut
func LogRequest(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (response interface{}, err error) {
fmt.Printf("Request for : %s\n", info.FullMethod)
// Last but super important, execute the handler so that the actualy gRPC request is also performed
return handler(ctx, req)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment