Last active
August 6, 2021 11:36
-
-
Save percybolmer/47f5c12d99e7c18efe3d2ba760a7535f to your computer and use it in GitHub Desktop.
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
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