Documentation ¶
Overview ¶
Package timeout is a middleware that responds with a timeout error after the given duration.
`grpc_timeout` are interceptors that timeout for gRPC client calls.
Client Side Timeout Middleware ¶
Please see examples for simple examples of use.
Example (Initialization) ¶
Initialization shows an initialization sequence with a custom client request timeout.
package main import ( "context" "log" "time" "github.com/tulzke/go-grpc-middleware/v2/interceptors/timeout" "github.com/tulzke/go-grpc-middleware/v2/testing/testpb" "google.golang.org/grpc" ) func main() { clientConn, err := grpc.Dial( "ServerAddr", grpc.WithUnaryInterceptor( // Set your client request timeout. timeout.UnaryClientInterceptor(20*time.Millisecond), ), ) if err != nil { log.Fatal(err) } // Initialize your grpc service with connection. testServiceClient := testpb.NewTestServiceClient(clientConn) resp, err := testServiceClient.Ping(context.TODO(), &testpb.PingRequest{Value: "my_example_value"}) if err != nil { log.Fatal(err) } // Use grpc response value. log.Println(resp.Value) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(timeout time.Duration) grpc.UnaryClientInterceptor
UnaryClientInterceptor returns a new unary client interceptor that sets a timeout on the request context.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.