Skip to content

Instantly share code, notes, and snippets.

@shijuvar
Last active May 28, 2018 15:08
Show Gist options
  • Save shijuvar/3a92a54a305eb3aa6edb798f0c8d157b to your computer and use it in GitHub Desktop.
Save shijuvar/3a92a54a305eb3aa6edb798f0c8d157b to your computer and use it in GitHub Desktop.
Register a server unary interceptor for authorization per RPC calls.
func init() {
grpcLog = grpclog.NewLoggerV2(os.Stdout, os.Stderr, os.Stderr)
grpclog.SetLoggerV2(grpcLog)
}
func main() {
lis, err := net.Listen("tcp", port)
if err != nil {
grpcLog.Fatalf("failed to listen: %v", err)
}
// Creates a new gRPC server with UnaryInterceptor
server := grpc.NewServer(
withServerUnaryInterceptor(),
)
pb.RegisterEventStoreServer(server, &eventStore{})
server.Serve(lis)
}
func withServerUnaryInterceptor() grpc.ServerOption {
return grpc.UnaryInterceptor(serverInterceptor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment