frostfs-api-go/rpc/client/client.go

39 lines
819 B
Go
Raw Permalink Normal View History

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