package grpctransport

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

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

Index

Examples

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

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

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.

Code:play 

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}}

Source Files

grpc_transport.go

Version
v1.74.0-dev
Published
May 15, 2025
Platform
darwin/amd64
Imports
9 packages
Last checked
1 hour ago

Tools for package owners.