middleware.go 832 B

123456789101112131415161718192021222324252627
  1. package middleware
  2. import (
  3. "github.com/grpc-ecosystem/go-grpc-middleware"
  4. "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
  5. "github.com/grpc-ecosystem/go-grpc-middleware/tags"
  6. "github.com/grpc-ecosystem/go-grpc-middleware/validator"
  7. "google.golang.org/grpc"
  8. )
  9. func GetStreamMiddleware() grpc.ServerOption {
  10. return grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
  11. grpc_ctxtags.StreamServerInterceptor(),
  12. grpc_validator.StreamServerInterceptor(),
  13. StreamServerFsLogInterceptor(),
  14. grpc_recovery.StreamServerInterceptor(),
  15. ))
  16. }
  17. func GetUnaryMiddleware() grpc.ServerOption {
  18. return grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
  19. grpc_ctxtags.UnaryServerInterceptor(),
  20. grpc_validator.UnaryServerInterceptor(),
  21. UnaryServerFsLogInterceptor(),
  22. grpc_recovery.UnaryServerInterceptor(),
  23. ))
  24. }