forked from grpc-ecosystem/go-grpc-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
38 lines (32 loc) · 962 Bytes
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) The go-grpc-middleware Authors.
// Licensed under the Apache License 2.0.
package timeout_test
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"
)
// Initialization shows an initialization sequence with a custom client request timeout.
func Example_initialization() {
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)
}