Last active
May 28, 2018 15:08
-
-
Save shijuvar/3a92a54a305eb3aa6edb798f0c8d157b to your computer and use it in GitHub Desktop.
Register a server unary interceptor for authorization per RPC calls.
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
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