MCPcopy
hub / github.com/grpc/grpc-go / chainUnaryClientInterceptors

Function chainUnaryClientInterceptors

clientconn.go:520–538  ·  view source on GitHub ↗

chainUnaryClientInterceptors chains all unary client interceptors into one.

(cc *ClientConn)

Source from the content-addressed store, hash-verified

518
519// chainUnaryClientInterceptors chains all unary client interceptors into one.
520func chainUnaryClientInterceptors(cc *ClientConn) {
521 interceptors := cc.dopts.chainUnaryInts
522 // Prepend dopts.unaryInt to the chaining interceptors if it exists, since unaryInt will
523 // be executed before any other chained interceptors.
524 if cc.dopts.unaryInt != nil {
525 interceptors = append([]UnaryClientInterceptor{cc.dopts.unaryInt}, interceptors...)
526 }
527 var chainedInt UnaryClientInterceptor
528 if len(interceptors) == 0 {
529 chainedInt = nil
530 } else if len(interceptors) == 1 {
531 chainedInt = interceptors[0]
532 } else {
533 chainedInt = func(ctx context.Context, method string, req, reply any, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error {
534 return interceptors[0](ctx, method, req, reply, cc, getChainUnaryInvoker(interceptors, 0, invoker), opts...)
535 }
536 }
537 cc.dopts.unaryInt = chainedInt
538}
539
540// getChainUnaryInvoker recursively generate the chained unary invoker.
541func getChainUnaryInvoker(interceptors []UnaryClientInterceptor, curr int, finalInvoker UnaryInvoker) UnaryInvoker {

Callers 1

NewClientFunction · 0.85

Calls 1

getChainUnaryInvokerFunction · 0.85

Tested by

no test coverage detected