Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/alexeyxo/go-grpc-middleware/v2

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/alexeyxo/go-grpc-middleware/v2

  • v2.0.3
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go gRPC Middleware V2

go Go Report Card GoDoc SourceGraph codecov Apache 2.0 License quality: production Slack

gRPC Go Middleware: interceptors, helpers, utilities.

NOTE: V2 is under development. If you want to be up to date, or better (!) help us improve go-grpc-middleware please follow on https://github.com/grpc-ecosystem/go-grpc-middleware/issues/275.

Middleware

gRPC Go recently acquired support for Interceptors, i.e. middleware that is executed either on the gRPC Server before the request is passed onto the user's application logic, or on the gRPC client either around the user call. It is a perfect way to implement common patterns: auth, logging, message, validation, retries or monitoring.

These are generic building blocks that make it easy to build multiple microservices easily. The purpose of this repository is to act as a go-to point for such reusable functionality. It contains some of them itself, but also will link to useful external repos.

middleware itself provides support for chaining interceptors, here's an example:

import "github.com/grpc-ecosystem/go-grpc-middleware/v2"

myServer := grpc.NewServer(
    grpc.ChainStreamInterceptor(
        tags.StreamServerInterceptor(),
        opentracing.StreamServerInterceptor(),
        prometheus.StreamServerInterceptor,
        zap.StreamServerInterceptor(zapLogger),
        auth.StreamServerInterceptor(myAuthFunction),
        recovery.StreamServerInterceptor(),
    ),
    grpc.ChainUnaryInterceptor(
        tags.UnaryServerInterceptor(),
        opentracing.UnaryServerInterceptor(),
        prometheus.UnaryServerInterceptor,
        zap.UnaryServerInterceptor(zapLogger),
        auth.UnaryServerInterceptor(myAuthFunction),
        recovery.UnaryServerInterceptor(),
    ),
)

Interceptors

Please send a PR to add new interceptors or middleware to this list

Auth
  • auth - a customizable (via AuthFunc) piece of auth middleware
Logging
  • tags - a library that adds a Tag map to context, with data populated from request body
  • zap - integration of zap logging library into gRPC handlers.
  • logrus - integration of logrus logging library into gRPC handlers.
  • kit - integration of go-kit logging library into gRPC handlers.
  • zerolog - integration of zerolog logging Library into gRPC handlers.
Monitoring
  • grpc_prometheus - Prometheus client-side and server-side monitoring middleware
  • opentracing - OpenTracing client-side and server-side interceptors with support for streaming and handler-returned tags
Client
  • retry - a generic gRPC response code retry mechanism, client-side middleware
  • timeout - a generic gRPC request timeout, client-side middleware
Server
  • validator - codegen inbound message validation from .proto options
  • recovery - turn panics into gRPC errors
  • ratelimit - grpc rate limiting by your own limiter
Utility
  • skip - allow users to skip interceptors in certain condition.

Status

This code has been running in production since May 2016 as the basis of the gRPC micro services stack at Improbable.

Additional tooling will be added, and contributions are welcome.

License

go-grpc-middleware is released under the Apache 2.0 license. See the LICENSE file for details.

FAQs

Package last updated on 19 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc