2021-03-12 12:33:32 +00:00
|
|
|
package client
|
|
|
|
|
2023-02-03 13:43:09 +00:00
|
|
|
import (
|
2023-03-17 12:54:33 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
2023-02-03 13:43:09 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials"
|
|
|
|
)
|
|
|
|
|
2021-03-12 12:33:32 +00:00
|
|
|
// Client represents client for exchanging messages
|
|
|
|
// with a remote server using Protobuf RPC.
|
|
|
|
type Client struct {
|
2023-02-03 12:22:00 +00:00
|
|
|
cfg
|
2021-03-12 12:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, configures via options and returns new Client instance.
|
|
|
|
func New(opts ...Option) *Client {
|
2023-02-03 12:22:00 +00:00
|
|
|
var c Client
|
|
|
|
c.initDefault()
|
2021-03-12 12:33:32 +00:00
|
|
|
|
|
|
|
for _, opt := range opts {
|
2023-02-03 12:22:00 +00:00
|
|
|
opt(&c.cfg)
|
2021-03-12 12:33:32 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 13:43:09 +00:00
|
|
|
if c.tlsCfg != nil {
|
|
|
|
c.grpcDialOpts = append(c.grpcDialOpts, grpc.WithTransportCredentials(credentials.NewTLS(c.tlsCfg)))
|
|
|
|
}
|
|
|
|
|
2023-03-17 12:54:33 +00:00
|
|
|
c.grpcDialOpts = append(c.grpcDialOpts,
|
|
|
|
grpc.WithChainUnaryInterceptor(
|
|
|
|
tracing.NewGRPCUnaryClientInteceptor(),
|
|
|
|
),
|
|
|
|
grpc.WithChainStreamInterceptor(
|
|
|
|
tracing.NewGRPCStreamClientInterceptor(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2023-02-03 12:22:00 +00:00
|
|
|
return &c
|
2021-03-12 12:33:32 +00:00
|
|
|
}
|