Example #1
0
// NewClientV3 creates a new grpc client connection to the member
func NewClientV3(m *member) (*clientv3.Client, error) {
	if m.grpcAddr == "" {
		return nil, fmt.Errorf("member not configured for grpc")
	}
	f := func(a string, t time.Duration) (net.Conn, error) {
		return net.Dial("unix", a)
	}
	unixdialer := grpc.WithDialer(f)
	opts := []grpc.DialOption{
		unixdialer,
		grpc.WithBlock(),
		grpc.WithTimeout(5 * time.Second)}
	if m.ClientTLSInfo != nil {
		tlscfg, err := m.ClientTLSInfo.ClientConfig()
		if err != nil {
			return nil, err
		}
		creds := credentials.NewTLS(tlscfg)
		opts = append(opts, grpc.WithTransportCredentials(creds))
	} else {
		opts = append(opts, grpc.WithInsecure())
	}
	conn, err := grpc.Dial(m.grpcAddr, opts...)
	if err != nil {
		return nil, err
	}
	return clientv3.NewFromConn(conn), nil
}
Example #2
0
// NewClientV3 creates a new grpc client connection to the member
func NewClientV3(m *member) (*clientv3.Client, error) {
	if m.grpcAddr == "" {
		return nil, fmt.Errorf("member not configured for grpc")
	}
	f := func(a string, t time.Duration) (net.Conn, error) {
		return net.Dial("unix", a)
	}
	unixdialer := grpc.WithDialer(f)
	conn, err := grpc.Dial(m.grpcAddr, grpc.WithInsecure(), unixdialer)
	if err != nil {
		return nil, err
	}
	return clientv3.NewFromConn(conn), nil
}