Scott Baker | eee8dd8 | 2019-09-24 12:52:34 -0700 | [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 tap defines the function handles which are executed on the transport |
| 20 | // layer of gRPC-Go and related information. Everything here is EXPERIMENTAL. |
| 21 | package tap |
| 22 | |
| 23 | import ( |
| 24 | "context" |
| 25 | ) |
| 26 | |
| 27 | // Info defines the relevant information needed by the handles. |
| 28 | type Info struct { |
| 29 | // FullMethodName is the string of grpc method (in the format of |
| 30 | // /package.service/method). |
| 31 | FullMethodName string |
| 32 | // TODO: More to be added. |
| 33 | } |
| 34 | |
| 35 | // ServerInHandle defines the function which runs before a new stream is created |
| 36 | // on the server side. If it returns a non-nil error, the stream will not be |
| 37 | // created and a RST_STREAM will be sent back to the client with REFUSED_STREAM. |
| 38 | // The client will receive an RPC error "code = Unavailable, desc = stream |
| 39 | // terminated by RST_STREAM with error code: REFUSED_STREAM". |
| 40 | // |
| 41 | // It's intended to be used in situations where you don't want to waste the |
| 42 | // resources to accept the new stream (e.g. rate-limiting). And the content of |
| 43 | // the error will be ignored and won't be sent back to the client. For other |
| 44 | // general usages, please use interceptors. |
| 45 | // |
| 46 | // Note that it is executed in the per-connection I/O goroutine(s) instead of |
| 47 | // per-RPC goroutine. Therefore, users should NOT have any |
| 48 | // blocking/time-consuming work in this handle. Otherwise all the RPCs would |
| 49 | // slow down. Also, for the same reason, this handle won't be called |
| 50 | // concurrently by gRPC. |
| 51 | type ServerInHandle func(ctx context.Context, info *Info) (context.Context, error) |