Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 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 | "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. 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. |
| 54 | type 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. |
| 60 | type 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. |
| 64 | type 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. |
| 77 | type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error |