timeout

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 26

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/grpc-ecosystem/go-grpc-middleware/v2/interceptors/timeout"
	"github.com/grpc-ecosystem/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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL