unaryInterceptor is an example unary interceptor.
(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption)
| 47 | |
| 48 | // unaryInterceptor is an example unary interceptor. |
| 49 | func unaryInterceptor(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { |
| 50 | var credsConfigured bool |
| 51 | for _, o := range opts { |
| 52 | _, ok := o.(grpc.PerRPCCredsCallOption) |
| 53 | if ok { |
| 54 | credsConfigured = true |
| 55 | break |
| 56 | } |
| 57 | } |
| 58 | if !credsConfigured { |
| 59 | opts = append(opts, grpc.PerRPCCredentials(oauth.TokenSource{ |
| 60 | TokenSource: oauth2.StaticTokenSource(&oauth2.Token{AccessToken: fallbackToken}), |
| 61 | })) |
| 62 | } |
| 63 | start := time.Now() |
| 64 | err := invoker(ctx, method, req, reply, cc, opts...) |
| 65 | end := time.Now() |
| 66 | logger("RPC: %s, start time: %s, end time: %s, err: %v", method, start.Format("Basic"), end.Format(time.RFC3339), err) |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | // wrappedStream wraps around the embedded grpc.ClientStream, and intercepts the RecvMsg and |
| 71 | // SendMsg method call. |
nothing calls this directly
no test coverage detected