grpctransport

package
v1.73.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package grpctransport provides an implementation of the clients.TransportBuilder interface using gRPC.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder creates gRPC-based Transports. It must be paired with ServerIdentifiers that contain an Extension field of type ServerIdentifierExtension.

func NewBuilder added in v1.73.0

func NewBuilder(configs map[string]Config) *Builder

NewBuilder provides a builder for creating gRPC-based Transports using the credentials from provided map of credentials names to credentials.Bundle.

func (*Builder) Build

Build returns a gRPC-based clients.Transport.

The Extension field of the ServerIdentifier must be a ServerIdentifierExtension.

type Config added in v1.73.0

type Config struct {
	// Credentials is the credentials bundle to be used for the connection.
	Credentials credentials.Bundle
	// GRPCNewClient is an optional custom function to establish a gRPC connection.
	// If nil, grpc.NewClient will be used as the default.
	GRPCNewClient func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
}

Config defines the configuration for connecting to a gRPC server, including credentials and an optional custom new client function.

type ServerIdentifierExtension

type ServerIdentifierExtension struct {
	// ConfigName is the name of the configuration to use for this transport.
	// It must be present as a key in the map of configs passed to NewBuilder.
	ConfigName string
}

ServerIdentifierExtension holds settings for connecting to a gRPC server, such as an xDS management or an LRS server.

It must be set by value (not pointer) in the clients.ServerIdentifier.Extensions field (See Example).

Example

ExampleServerIdentifierExtension demonstrates how to create clients.ServerIdentifier with grpctransport.ServerIdentifierExtension as its extensions.

This example is creating clients.ServerIdentifier to connect to server at localhost:5678 using the config named "local". Note that "local" must exist as an entry in the provided configs to grpctransport.Builder.

package main

import (
	"fmt"

	"google.golang.org/grpc/xds/internal/clients"
	"google.golang.org/grpc/xds/internal/clients/grpctransport"
)

func main() {
	// Note the Extensions field is set by value and not by pointer.
	fmt.Printf("%+v", clients.ServerIdentifier{ServerURI: "localhost:5678", Extensions: grpctransport.ServerIdentifierExtension{ConfigName: "local"}})
}
Output:

{ServerURI:localhost:5678 Extensions:{ConfigName:local}}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL