@@ -30,11 +30,14 @@ types of interceptors in total.
3030
3131The type for client-side unary interceptors is
3232[ ` UnaryClientInterceptor ` ] ( https://godoc.org/google.golang.org/grpc#UnaryClientInterceptor ) .
33- It is essentially a function type with signature: `func(ctx context.Context,
34- method string, req, reply interface{}, cc * ClientConn, invoker UnaryInvoker,
35- opts ...CallOption) error`. Unary interceptor implementations can usually be
36- divided into three parts: pre-processing, invoking the RPC method, and
37- post-processing.
33+ It is a function type with signature:
34+
35+ ``` golang
36+ func (ctx context .Context , method string , req , reply interface {}, cc *ClientConn , invoker UnaryInvoker , opts ...CallOption ) error
37+ ```
38+
39+ Unary interceptor implementations can usually be divided into three parts:
40+ pre-processing, invoking the RPC method, and post-processing.
3841
3942For pre-processing, users can get info about the current RPC call by examining
4043the args passed in. The args include the RPC context, method string, request to
@@ -59,22 +62,26 @@ To install a unary interceptor on a ClientConn, configure `Dial` with the
5962
6063The type for client-side stream interceptors is
6164[`StreamClientInterceptor`](https:// godoc.org/google.golang.org/grpc#StreamClientInterceptor).
62- It is a function type with signature: `func(ctx context.Context, desc
63- * StreamDesc, cc * ClientConn, method string, streamer Streamer, opts
64- ...CallOption) (ClientStream, error)`. An implementation of a stream interceptor
65- usually includes pre-processing, and stream operation interception.
65+ It is a function type with signature:
66+
67+ ```golang
68+ func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error)
69+ ```
70+
71+ An implementation of a stream interceptor usually includes pre-processing, and
72+ stream operation interception.
6673
6774The pre-processing is similar to unary interceptors.
6875
6976However, rather than invoking the RPC method followed by post-processing, stream
7077interceptors intercept the users' operations on the stream. The interceptor
7178first calls the passed-in `streamer` to get a `ClientStream`, and then wraps the
72- ` ClientStream ` while overloading its methods with the interception logic.
79+ `ClientStream` while overriding its methods with the interception logic.
7380Finally, the interceptor returns the wrapped `ClientStream` to user to operate
7481on.
7582
7683In the example, we define a new struct `wrappedStream`, which embeds a
77- ` ClientStream ` . We then implement (overload ) the ` SendMsg ` and ` RecvMsg ` methods
84+ `ClientStream`. We then implement (override ) the `SendMsg` and `RecvMsg` methods
7885on `wrappedStream` to intercept these two operations on the embedded
7986`ClientStream`. In the example, we log the message type info and time info for
8087interception purpose.
@@ -92,9 +99,11 @@ different information provided as args.
9299
93100The type for server-side unary interceptors is
94101[`UnaryServerInterceptor`](https:// godoc.org/google.golang.org/grpc#UnaryServerInterceptor).
95- It is a function type with signature: `func(ctx context.Context, req
96- interface{}, info * UnaryServerInfo, handler UnaryHandler) (resp interface{}, err
97- error)`.
102+ It is a function type with signature:
103+
104+ ```golang
105+ func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler ) (resp interface {}, err error )
106+ ```
98107
99108Refer to the client-side unary interceptor section for a detailed implementation
100109and explanation.
@@ -107,13 +116,15 @@ To install a unary interceptor on a Server, configure `NewServer` with the
107116
108117The type for server-side stream interceptors is
109118[ ` StreamServerInterceptor ` ] ( https://godoc.org/google.golang.org/grpc#StreamServerInterceptor ) .
110- It is a function type with the signature: `func(srv interface{}, ss
111- ServerStream, info * StreamServerInfo, handler StreamHandler) error`.
119+ It is a function type with the signature:
120+
121+ ``` golang
122+ func (srv interface {}, ss ServerStream , info *StreamServerInfo , handler StreamHandler ) error
123+ ```
112124
113125Refer to the client-side stream interceptor section for a detailed
114126implementation and explanation.
115127
116128To install a stream interceptor on a Server, configure `NewServer` with the
117129[`StreamInterceptor`](https:// godoc.org/google.golang.org/grpc#StreamInterceptor)
118130`ServerOption`.
119-
0 commit comments