OSDN Git Service

new repo
[bytom/vapor.git] / vendor / google.golang.org / grpc / interceptor.go
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * 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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * 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.
16  *
17  */
18
19 package grpc
20
21 import (
22         "golang.org/x/net/context"
23 )
24
25 // UnaryInvoker is called by UnaryClientInterceptor to complete RPCs.
26 type UnaryInvoker func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error
27
28 // UnaryClientInterceptor intercepts the execution of a unary RPC on the client. invoker is the handler to complete the RPC
29 // and it is the responsibility of the interceptor to call it.
30 // This is an EXPERIMENTAL API.
31 type 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.
34 type 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
37 // 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.
39 type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error)
40
41 // UnaryServerInfo consists of various information about a unary RPC on
42 // server side. All per-rpc information may be mutated by the interceptor.
43 type 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
51 // execution of a unary RPC.
52 type UnaryHandler func(ctx context.Context, req interface{}) (interface{}, error)
53
54 // UnaryServerInterceptor provides a hook to intercept the execution of a unary RPC on the server. info
55 // contains all the information of this RPC the interceptor can operate on. And handler is the wrapper
56 // of the service method implementation. It is the responsibility of the interceptor to invoke handler
57 // to complete the RPC.
58 type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (resp interface{}, err error)
59
60 // StreamServerInfo consists of various information about a streaming RPC on
61 // server side. All per-rpc information may be mutated by the interceptor.
62 type StreamServerInfo struct {
63         // FullMethod is the full RPC method string, i.e., /package.service/method.
64         FullMethod string
65         // IsClientStream indicates whether the RPC is a client streaming RPC.
66         IsClientStream bool
67         // IsServerStream indicates whether the RPC is a server streaming RPC.
68         IsServerStream bool
69 }
70
71 // StreamServerInterceptor provides a hook to intercept the execution of a streaming RPC on the server.
72 // info contains all the information of this RPC the interceptor can operate on. And handler is the
73 // service method implementation. It is the responsibility of the interceptor to invoke handler to
74 // complete the RPC.
75 type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error