blob: 1f6ef678035b435a001c9a93412c839843d341aa [file] [log] [blame]
iamqizhao61e92ea2016-04-18 23:18:341/*
2 *
Jan Tattermuschddbf6c42017-06-08 12:42:193 * Copyright 2016 gRPC authors.
iamqizhao61e92ea2016-04-18 23:18:344 *
Jan Tattermuschddbf6c42017-06-08 12:42:195 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
iamqizhao61e92ea2016-04-18 23:18:348 *
Jan Tattermuschddbf6c42017-06-08 12:42:199 * http://www.apache.org/licenses/LICENSE-2.0
iamqizhao61e92ea2016-04-18 23:18:3410 *
Jan Tattermuschddbf6c42017-06-08 12:42:1911 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
iamqizhao61e92ea2016-04-18 23:18:3416 *
17 */
18
19package grpc
20
21import (
22 "golang.org/x/net/context"
23)
24
iamqizhao1e47e172016-08-26 20:50:3825// UnaryInvoker is called by UnaryClientInterceptor to complete RPCs.
26type UnaryInvoker func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error
27
marcushines9f9c1902017-04-06 20:50:2328// UnaryClientInterceptor intercepts the execution of a unary RPC on the client. invoker is the handler to complete the RPC
iamqizhao1e47e172016-08-26 20:50:3829// and it is the responsibility of the interceptor to call it.
Adele Zhou7ddf89f2017-05-04 17:16:2930// This is an EXPERIMENTAL API.
iamqizhao1e47e172016-08-26 20:50:3831type UnaryClientInterceptor func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error
32
33// Streamer is called by StreamClientInterceptor to create a ClientStream.
34type Streamer func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (ClientStream, error)
35
36// StreamClientInterceptor intercepts the creation of ClientStream. It may return a custom ClientStream to intercept all I/O
Adele Zhou7ddf89f2017-05-04 17:16:2937// operations. streamer is the handler to create a ClientStream and it is the responsibility of the interceptor to call it.
38// This is an EXPERIMENTAL API.
iamqizhao1e47e172016-08-26 20:50:3839type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error)
40
iamqizhao61e92ea2016-04-18 23:18:3441// UnaryServerInfo consists of various information about a unary RPC on
42// server side. All per-rpc information may be mutated by the interceptor.
43type UnaryServerInfo struct {
44 // Server is the service implementation the user provides. This is read-only.
45 Server interface{}
46 // FullMethod is the full RPC method string, i.e., /package.service/method.
47 FullMethod string
48}
49
50// UnaryHandler defines the handler invoked by UnaryServerInterceptor to complete the normal
Jean de Klerk9aba0442018-03-08 21:46:2651// execution of a unary RPC. If a UnaryHandler returns an error, it should be produced by the
52// status package, or else gRPC will use codes.Unknown as the status code and err.Error() as
53// the status message of the RPC.
iamqizhao61e92ea2016-04-18 23:18:3454type UnaryHandler func(ctx context.Context, req interface{}) (interface{}, error)
55
56// UnaryServerInterceptor provides a hook to intercept the execution of a unary RPC on the server. info
57// contains all the information of this RPC the interceptor can operate on. And handler is the wrapper
58// of the service method implementation. It is the responsibility of the interceptor to invoke handler
59// to complete the RPC.
60type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (resp interface{}, err error)
61
62// StreamServerInfo consists of various information about a streaming RPC on
63// server side. All per-rpc information may be mutated by the interceptor.
64type StreamServerInfo struct {
65 // FullMethod is the full RPC method string, i.e., /package.service/method.
66 FullMethod string
67 // IsClientStream indicates whether the RPC is a client streaming RPC.
68 IsClientStream bool
69 // IsServerStream indicates whether the RPC is a server streaming RPC.
70 IsServerStream bool
71}
72
73// StreamServerInterceptor provides a hook to intercept the execution of a streaming RPC on the server.
74// info contains all the information of this RPC the interceptor can operate on. And handler is the
75// service method implementation. It is the responsibility of the interceptor to invoke handler to
76// complete the RPC.
77type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error