客户端拦截器

接口实现

  • 如需添加拦截器,则需实现如下功能

  • 然后通过client.AddInterceptor注册拦截器,之后服务启动时将会通过配置调用相应的拦截器


// ClientInterceptor defines the interface for a client-side interceptor.
// Implementing this allows a module to provide metadata and the actual interceptor logic.
type ClientInterceptor interface {
	// Name returns the unique identifier of the interceptor.
	Name() string
	// Interceptor returns the functional UnaryClientInterceptor.
	Interceptor() UnaryClientInterceptor
}

// UnaryClientInterceptor is a function that intercepts a unary RPC call.
// It can perform logic before and after the invoker is called, such as logging,
// tracing, or modifying request metadata.
type UnaryClientInterceptor func(ctx context.Context, method string, req, reply any, cc ClientConnInterface, invoker UnaryInvoker) error

已支持的实现

配置

更新默认拦截器:

自定义实现

最后更新于