khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [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. |
| 21 | // |
Joey Armstrong | ba3d9d1 | 2024-01-15 14:22:11 -0500 | [diff] [blame] | 22 | // # Experimental |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 23 | // |
| 24 | // Notice: This API is EXPERIMENTAL and may be changed or removed in a |
| 25 | // later release. |
| 26 | package tap |
| 27 | |
| 28 | import ( |
| 29 | "context" |
| 30 | ) |
| 31 | |
| 32 | // Info defines the relevant information needed by the handles. |
| 33 | type Info struct { |
| 34 | // FullMethodName is the string of grpc method (in the format of |
| 35 | // /package.service/method). |
| 36 | FullMethodName string |
| 37 | // TODO: More to be added. |
| 38 | } |
| 39 | |
| 40 | // ServerInHandle defines the function which runs before a new stream is |
| 41 | // created on the server side. If it returns a non-nil error, the stream will |
| 42 | // not be created and an error will be returned to the client. If the error |
| 43 | // returned is a status error, that status code and message will be used, |
| 44 | // otherwise PermissionDenied will be the code and err.Error() will be the |
| 45 | // message. |
| 46 | // |
| 47 | // It's intended to be used in situations where you don't want to waste the |
| 48 | // resources to accept the new stream (e.g. rate-limiting). For other general |
| 49 | // usages, please use interceptors. |
| 50 | // |
| 51 | // Note that it is executed in the per-connection I/O goroutine(s) instead of |
| 52 | // per-RPC goroutine. Therefore, users should NOT have any |
| 53 | // blocking/time-consuming work in this handle. Otherwise all the RPCs would |
| 54 | // slow down. Also, for the same reason, this handle won't be called |
| 55 | // concurrently by gRPC. |
| 56 | type ServerInHandle func(ctx context.Context, info *Info) (context.Context, error) |