• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

auth/H12-Sep-2019-

logging/H12-Sep-2019-

ratelimit/H12-Sep-2019-

recovery/H12-Sep-2019-

retry/H12-Sep-2019-

scripts/H12-Sep-2019-

tags/H12-Sep-2019-

testing/H12-Sep-2019-

tracing/opentracing/H12-Sep-2019-

util/H12-Sep-2019-

validator/H12-Sep-2019-

.gitignoreH A D12-Sep-20193.2 KiB

.travis.ymlH A D12-Sep-2019171

CHANGELOG.mdH A D12-Sep-2019845

CONTRIBUTING.mdH A D12-Sep-2019422

LICENSEH A D12-Sep-201911.1 KiB

README.mdH A D12-Sep-20194.7 KiB

chain.goH A D12-Sep-20195.1 KiB

chain_test.goH A D12-Sep-20199 KiB

doc.goH A D12-Sep-20193 KiB

go.modH A D12-Sep-2019613

go.sumH A D12-Sep-20197.1 KiB

makefileH A D12-Sep-2019285

wrappers.goH A D12-Sep-2019929

wrappers_test.goH A D12-Sep-20191.3 KiB

README.md

1# Go gRPC Middleware
2
3[![Travis Build](https://travis-ci.org/grpc-ecosystem/go-grpc-middleware.svg?branch=master)](https://travis-ci.org/grpc-ecosystem/go-grpc-middleware)
4[![Go Report Card](https://goreportcard.com/badge/github.com/grpc-ecosystem/go-grpc-middleware)](https://goreportcard.com/report/github.com/grpc-ecosystem/go-grpc-middleware)
5[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/grpc-ecosystem/go-grpc-middleware)
6[![SourceGraph](https://sourcegraph.com/github.com/grpc-ecosystem/go-grpc-middleware/-/badge.svg)](https://sourcegraph.com/github.com/grpc-ecosystem/go-grpc-middleware/?badge)
7[![codecov](https://codecov.io/gh/grpc-ecosystem/go-grpc-middleware/branch/master/graph/badge.svg)](https://codecov.io/gh/grpc-ecosystem/go-grpc-middleware)
8[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
9[![quality: production](https://img.shields.io/badge/quality-production-orange.svg)](#status)
10[![Slack](slack.png)](https://join.slack.com/t/improbable-eng/shared_invite/enQtMzQ1ODcyMzQ5MjM4LWY5ZWZmNGM2ODc5MmViNmQ3ZTA3ZTY3NzQwOTBlMTkzZmIxZTIxODk0OWU3YjZhNWVlNDU3MDlkZGViZjhkMjc)
11
12[gRPC Go](https://github.com/grpc/grpc-go) Middleware: interceptors, helpers, utilities.
13
14## Middleware
15
16[gRPC Go](https://github.com/grpc/grpc-go) recently acquired support for
17Interceptors, i.e. [middleware](https://medium.com/@matryer/writing-middleware-in-golang-and-how-go-makes-it-so-much-fun-4375c1246e81#.gv7tdlghs)
18that 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
19common patterns: auth, logging, message, validation, retries or monitoring.
20
21These are generic building blocks that make it easy to build multiple microservices easily.
22The purpose of this repository is to act as a go-to point for such reusable functionality. It contains
23some of them itself, but also will link to useful external repos.
24
25`grpc_middleware` itself provides support for chaining interceptors, here's an example:
26
27```go
28import "github.com/grpc-ecosystem/go-grpc-middleware"
29
30myServer := grpc.NewServer(
31    grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
32        grpc_ctxtags.StreamServerInterceptor(),
33        grpc_opentracing.StreamServerInterceptor(),
34        grpc_prometheus.StreamServerInterceptor,
35        grpc_zap.StreamServerInterceptor(zapLogger),
36        grpc_auth.StreamServerInterceptor(myAuthFunction),
37        grpc_recovery.StreamServerInterceptor(),
38    )),
39    grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
40        grpc_ctxtags.UnaryServerInterceptor(),
41        grpc_opentracing.UnaryServerInterceptor(),
42        grpc_prometheus.UnaryServerInterceptor,
43        grpc_zap.UnaryServerInterceptor(zapLogger),
44        grpc_auth.UnaryServerInterceptor(myAuthFunction),
45        grpc_recovery.UnaryServerInterceptor(),
46    )),
47)
48```
49
50## Interceptors
51
52*Please send a PR to add new interceptors or middleware to this list*
53
54#### Auth
55   * [`grpc_auth`](auth) - a customizable (via `AuthFunc`) piece of auth middleware
56
57#### Logging
58   * [`grpc_ctxtags`](tags/) - a library that adds a `Tag` map to context, with data populated from request body
59   * [`grpc_zap`](logging/zap/) - integration of [zap](https://github.com/uber-go/zap) logging library into gRPC handlers.
60   * [`grpc_logrus`](logging/logrus/) - integration of [logrus](https://github.com/sirupsen/logrus) logging library into gRPC handlers.
61
62
63#### Monitoring
64   * [`grpc_prometheus`⚡](https://github.com/grpc-ecosystem/go-grpc-prometheus) - Prometheus client-side and server-side monitoring middleware
65   * [`otgrpc`⚡](https://github.com/grpc-ecosystem/grpc-opentracing/tree/master/go/otgrpc) - [OpenTracing](http://opentracing.io/) client-side and server-side interceptors
66   * [`grpc_opentracing`](tracing/opentracing) - [OpenTracing](http://opentracing.io/) client-side and server-side interceptors with support for streaming and handler-returned tags
67
68#### Client
69   * [`grpc_retry`](retry/) - a generic gRPC response code retry mechanism, client-side middleware
70
71#### Server
72   * [`grpc_validator`](validator/) - codegen inbound message validation from `.proto` options
73   * [`grpc_recovery`](recovery/) - turn panics into gRPC errors
74   * [`ratelimit`](ratelimit/) - grpc rate limiting by your own limiter
75
76
77## Status
78
79This code has been running in *production* since May 2016 as the basis of the gRPC micro services stack at [Improbable](https://improbable.io).
80
81Additional tooling will be added, and contributions are welcome.
82
83## License
84
85`go-grpc-middleware` is released under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.
86