Client interceptor

Interface implementation

  • To add an interceptor, you need to implement the following functionality

  • Then viaclient.AddInterceptorregister the interceptor; afterwards when the service starts it will call the corresponding interceptor through configuration


// 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

Supported implementations

Configuration

Update default interceptors:

Custom implementation

Last updated