grpcreflect

package
v2.0.0-...-c9ae7ca Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Overview

Package grpcreflect provides gRPC-specific extensions to protobuf reflection. This includes a way to access rich service descriptors for all services that a gRPC server exports.

Also included is an easy-to-use client for the gRPC reflection service. This client makes it easy to ask a server (that supports the reflection service) for metadata on its exported services, which could be used to construct a dynamic client. (See the grpcdynamic package in this same repo for more on that.)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsElementNotFoundError

func IsElementNotFoundError(err error) bool

IsElementNotFoundError determines if the given error indicates that a file name, symbol name, or extension field was could not be found by the server.

func LoadServiceDescriptor

func LoadServiceDescriptor(svc *grpc.ServiceDesc) (protoreflect.ServiceDescriptor, error)

LoadServiceDescriptor loads a rich descriptor for a given service description generated by protoc-gen-go. Generated code contains an unexported symbol with a name like "_<Service>_serviceDesc" which is the service's description. It is used internally to register a service implementation with a GRPC server. But it can also be used by this package to retrieve the rich descriptor for the service.

func LoadServiceDescriptors

func LoadServiceDescriptors(s GRPCServer) (map[string]protoreflect.ServiceDescriptor, error)

LoadServiceDescriptors loads the service descriptors for all services exposed by the given GRPC server.

Types

type Client

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

Client is a client connection to a server for performing reflection calls and resolving remote symbols.

func NewClientAuto

func NewClientAuto(ctx context.Context, cc grpc.ClientConnInterface) *Client

NewClientAuto creates a new Client that will use either v1 or v1alpha version of reflection (based on what the server supports) with the given root context and using the given client connection.

It will first the v1 version of the reflection service. If it gets back an "Unimplemented" error, it will fall back to using the v1alpha version. It will remember which version the server supports for any subsequent operations that need to re-invoke the streaming RPC. But, if it's a very long-lived client, it will periodically retry the v1 version (in case the server is updated to support it also). The period for these retries is every hour.

func NewClientV1

func NewClientV1(ctx context.Context, stub refv1.ServerReflectionClient) *Client

NewClientV1 creates a new Client using the v1 version of reflection with the given root context and using the given RPC stub for talking to the server.

func NewClientV1Alpha

func NewClientV1Alpha(ctx context.Context, stub refv1alpha.ServerReflectionClient) *Client

NewClientV1Alpha creates a new Client using the v1alpha version of reflection with the given root context and using the given RPC stub for talking to the server.

func (*Client) AllExtensionNumbersForType

func (cr *Client) AllExtensionNumbersForType(extendedMessageName protoreflect.FullName) ([]protoreflect.FieldNumber, error)

AllExtensionNumbersForType asks the server for all known extension numbers for the given fully-qualified message name.

func (*Client) AsResolver

func (cr *Client) AsResolver() protoresolve.Resolver

AsResolver returns a protoresolve.Resolver that is backed by this client. Iteration via the various Range methods will only enumerate the snapshot of known elements at the time iteration starts. If more elements are discovered, via subsequent calls to the server to handle other queries, they will then be available to later iterations. That means that calls to NumFiles and NumFilesByPackage are not necessarily authoritative as the actual number could change concurrently.

func (*Client) FileByFilename

func (cr *Client) FileByFilename(filename string) (protoreflect.FileDescriptor, error)

FileByFilename asks the server for a file descriptor for the proto file with the given name.

func (*Client) FileContainingExtension

func (cr *Client) FileContainingExtension(extendedMessageName protoreflect.FullName, extensionNumber protoreflect.FieldNumber) (protoreflect.FileDescriptor, error)

FileContainingExtension asks the server for a file descriptor for the proto file that declares an extension with the given number for the given fully-qualified message name.

func (*Client) FileContainingSymbol

func (cr *Client) FileContainingSymbol(symbol protoreflect.FullName) (protoreflect.FileDescriptor, error)

FileContainingSymbol asks the server for a file descriptor for the proto file that declares the given fully-qualified symbol.

func (*Client) ListServices

func (cr *Client) ListServices() ([]protoreflect.FullName, error)

ListServices asks the server for the fully-qualified names of all exposed services.

func (*Client) Reset

func (cr *Client) Reset()

Reset ensures that any active stream with the server is closed, releasing any resources.

type GRPCServer

type GRPCServer = reflection.GRPCServer

GRPCServer is the interface provided by a gRPC server. In addition to being a service registrar (for registering services and handlers), it also has an accessor for retrieving metadata about all registered services.

type ProtocolError

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

ProtocolError is an error returned when the server sends a response of the wrong type.

func (ProtocolError) Error

func (p ProtocolError) Error() string

Jump to

Keyboard shortcuts

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