Created
March 10, 2022 16:11
-
-
Save harunpeksen/4d1e388381677d9aad4501e65651ad8d to your computer and use it in GitHub Desktop.
This file contains 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
// 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