-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient.go
30 lines (23 loc) · 926 Bytes
/
client.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
package messaging
import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
messagingpb "github.com/code-payments/code-protobuf-api/generated/go/messaging/v1"
"github.com/code-payments/code-server/pkg/grpc/headers"
"github.com/code-payments/code-server/pkg/grpc/protobuf/validation"
)
// todo: we can cache and reuse clients
func getInternalMessagingClient(target string) (messagingpb.MessagingClient, func() error, error) {
conn, err := grpc.Dial(
target,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithUnaryInterceptor(validation.UnaryClientInterceptor()),
grpc.WithUnaryInterceptor(headers.UnaryClientInterceptor()),
grpc.WithStreamInterceptor(validation.StreamClientInterceptor()),
grpc.WithStreamInterceptor(headers.StreamClientInterceptor()),
)
if err != nil {
return nil, nil, err
}
return messagingpb.NewMessagingClient(conn), conn.Close, nil
}