Skip to main content
Version: 2.8.x(Latest)

GRPC supports interceptor features, enhancing the flexibility and extensibility of GRPC.

Interceptor Usage

Server

Use grpcx.Server.ChainUnary to add extra server interceptors:

c := grpcx.Server.NewConfig()
c.Options = append(c.Options, []grpc.ServerOption{
grpcx.Server.ChainUnary(
grpcx.Server.UnaryValidate,
)}...,
)
s := grpcx.Server.New(c)
user.Register(s)
s.Run()

Client

Use grpcx.Client.ChainUnary to add extra server interceptors:

conn = grpcx.Client.MustNewGrpcClientConn("demo", grpcx.Client.ChainUnary(
grpcx.Client.UnaryTracing,
))

Interceptor List

The grpcx component of the framework offers a series of commonly used interceptors, some built-in and others optional.

InterceptorUsage PartBuilt-inDescription
UnaryErrorClientYesSupports the framework's error handling component.
UnaryTracingClientYesSupports link tracing.
StreamTracingClientYesSupports link tracing (long connection).
UnaryErrorServerYesSupports the framework's error handling component.
UnaryRecoverServerYesSupports automatic capture of server panic without crashing.
UnaryAllowNilResServerYesSupports returning nil Res objects.
UnaryValidateServerNoSupports the framework's automatic error validation, based on struct tags. Needs to be manually introduced.
UnaryTracingServerYesSupports link tracing.
StreamTracingServerYesSupports link tracing (long connection).