chainUnaryClientInterceptors chains all unary client interceptors into one.
(cc *ClientConn)
| 518 | |
| 519 | // chainUnaryClientInterceptors chains all unary client interceptors into one. |
| 520 | func 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. |
| 541 | func getChainUnaryInvoker(interceptors []UnaryClientInterceptor, curr int, finalInvoker UnaryInvoker) UnaryInvoker { |
no test coverage detected