grpcreflect

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 19 Imported by: 249

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 (https://goo.gl/2ILAHf). 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) (*desc.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]*desc.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 NewClient deprecated

NewClient creates a new Client with the given root context and using the given RPC stub for talking to the server.

Deprecated: Use NewClientV1Alpha if you are intentionally pinning the v1alpha version of the reflection service. Otherwise, use NewClientAuto instead.

func NewClientAuto added in v1.14.0

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 NewClientV1Alpha added in v1.14.0

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 string) ([]int32, error)

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

func (*Client) AllowMissingFileDescriptors added in v1.16.0

func (cr *Client) AllowMissingFileDescriptors()

AllowMissingFileDescriptors configures the client to allow missing files when building descriptors when possible. Missing files are often fatal errors, but with this option they can sometimes be worked around. Building a schema can only succeed with some files missing if the files in question only provide custom options and/or other unused types.

func (*Client) FileByFilename

func (cr *Client) FileByFilename(filename string) (*desc.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 string, extensionNumber int32) (*desc.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 string) (*desc.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() ([]string, 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.

func (*Client) ResolveEnum

func (cr *Client) ResolveEnum(enumName string) (*desc.EnumDescriptor, error)

ResolveEnum asks the server to resolve the given fully-qualified enum name into an enum descriptor.

func (*Client) ResolveEnumValues

func (cr *Client) ResolveEnumValues(enumName string) (map[string]int32, error)

ResolveEnumValues asks the server to resolve the given fully-qualified enum name into a map of names to numbers that represents the enum's values.

func (*Client) ResolveExtension

func (cr *Client) ResolveExtension(extendedType string, extensionNumber int32) (*desc.FieldDescriptor, error)

ResolveExtension asks the server to resolve the given extension number and fully-qualified message name into a field descriptor.

func (*Client) ResolveMessage

func (cr *Client) ResolveMessage(messageName string) (*desc.MessageDescriptor, error)

ResolveMessage asks the server to resolve the given fully-qualified message name into a message descriptor.

func (*Client) ResolveService

func (cr *Client) ResolveService(serviceName string) (*desc.ServiceDescriptor, error)

ResolveService asks the server to resolve the given fully-qualified service name into a service descriptor.

type GRPCServer added in v1.11.0

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