Middleware
- rpclog
- duration
- validator
- grpc-opentracing
Get
go get github.com/xmlking/toolkit
Usage
Interceptors will be executed from left to right: e.g., logging, monitoring and auth.
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(loggingUnary, monitoringUnary, authUnary),)
Add interceptors in following order
- Around interceptors - from outer to inner — e.g., duration, retry
- Before interceptors - rate-limit, auth, validation , tagging
- After interceptors - rpclog, translog, recovery
import (
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_validator "github.com/grpc-ecosystem/go-grpc-middleware/validator"
"github.com/xmlking/toolkit/middleware/rpclog"
)
server := grpc.NewServer(
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
// Execution is done in left-to-right order
grpc_validator.UnaryServerInterceptor(),
// keep it last in the interceptor chain
rpclog.UnaryServerInterceptor(rpclog.WithExcludeMethods("/grpc.health.v1.Health/Check", "/api.MyService/*")),
)),
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
// keep it last in the interceptor chain
rpclog.StreamServerInterceptor()
)),
)