Documentation
¶
Overview ¶
Package grpcurl provides the core functionality exposed by the grpcurl command, for dynamically connecting to a server, using the reflection service to inspect the server, and invoking RPCs. The grpcurl command-line tool constructs a DescriptorSource, based on the command-line parameters, and supplies an InvocationEventHandler to supply request data (which can come from command-line args or the process's stdin) and to log the events (to the process's stdout).
Package proto provides functionality for handling protocol buffer messages. In particular, it provides marshaling and unmarshaling between a protobuf message and the binary wire format.
See https://developers.google.com/protocol-buffers/docs/gotutorial for more information.
Deprecated: Use the "google.golang.org/protobuf/proto" package instead.
Index ¶
- Constants
- Variables
- func AnyResolverFromDescriptorSource(source DescriptorSource) jsonpb.AnyResolver
- func AnyResolverFromDescriptorSourceWithFallback(source DescriptorSource) jsonpb.AnyResolver
- func BlockingDial(ctx context.Context, network, address string, ...) (*grpc.ClientConn, error)
- func ClientTLSConfig(insecureSkipVerify bool, cacertFile, clientCertFile, clientKeyFile string) (*tls.Config, error)
- func ClientTransportCredentials(insecureSkipVerify bool, cacertFile, clientCertFile, clientKeyFile string) (credentials.TransportCredentials, error)deprecated
- func CompactText(w io.Writer, m Message) error
- func CompactTextString(m Message) string
- func Dial(ctx context.Context, address string) (*grpc.ClientConn, error)
- func EnsureExtensions(source DescriptorSource, msg proto.Message) proto.Message
- func Equal(x, y Message) bool
- func ExpandHeaders(headers []string) ([]string, error)
- func GetAllFiles(source DescriptorSource) ([]*desc.FileDescriptor, error)
- func GetDescriptorText(dsc desc.Descriptor, _ DescriptorSource) (string, error)
- func InvokeRPC(ctx context.Context, source DescriptorSource, ch grpcdynamic.Channel, ...) error
- func InvokeRpc(ctx context.Context, source DescriptorSource, cc *grpc.ClientConn, ...) errordeprecated
- func ListMethods(source DescriptorSource, serviceName string) ([]string, error)
- func ListServiceMethod(ctx context.Context, address string, headerList ...http.Header) (annotation map[string]*Annotation, err error)
- func ListServices(source DescriptorSource) ([]string, error)
- func MakeTemplate(md *desc.MessageDescriptor) proto.Message
- func MarshalText(w io.Writer, m Message) error
- func MarshalTextString(m Message) string
- func Merge(dst, src Message)
- func MessageReflect(m Message) protoreflect.Message
- func MessageV1(m GeneratedMessage) protoiface.MessageV1
- func MessageV2(m GeneratedMessage) protoV2.Message
- func MetadataFromHeaders(headers []string) metadata.MD
- func MetadataToString(md metadata.MD) string
- func PrintStatus(w io.Writer, stat *status.Status, formatter Formatter)
- func RequestParserAndFormatter(format Format, descSource DescriptorSource, in io.Reader, opts FormatOptions) (RequestParser, Formatter, error)
- func RequestParserAndFormatterFor(format Format, descSource DescriptorSource, ...) (RequestParser, Formatter, error)
- func ServerTransportCredentials(cacertFile, serverCertFile, serverKeyFile string, requireClientCerts bool) (credentials.TransportCredentials, error)
- func WriteProtoset(out io.Writer, descSource DescriptorSource, symbols ...string) error
- type Annotation
- type CommentType
- type DefaultEventHandler
- func (h *DefaultEventHandler) OnReceiveHeaders(md metadata.MD)
- func (h *DefaultEventHandler) OnReceiveResponse(resp proto.Message)
- func (h *DefaultEventHandler) OnReceiveTrailers(stat *status.Status, md metadata.MD)
- func (h *DefaultEventHandler) OnResolveMethod(md *desc.MethodDescriptor)
- func (h *DefaultEventHandler) OnSendHeaders(md metadata.MD)
- type DescriptorSource
- func DescriptorSourceFromFileDescriptorSet(files *descriptorpb.FileDescriptorSet) (DescriptorSource, error)
- func DescriptorSourceFromFileDescriptors(files ...*desc.FileDescriptor) (DescriptorSource, error)
- func DescriptorSourceFromProtoFiles(importPaths []string, fileNames ...string) (DescriptorSource, error)
- func DescriptorSourceFromProtoSets(fileNames ...string) (DescriptorSource, error)
- func DescriptorSourceFromServer(_ context.Context, refClient *grpcreflect.Client) DescriptorSource
- func GetDescSource(ctx context.Context, address string, headerList ...http.Header) (DescriptorSource, error)
- type Element
- type ElementKind
- type Format
- type FormatOptions
- type Formatter
- type GeneratedEnum
- type GeneratedMessage
- type InvocationEventHandler
- type Marshalerdeprecated
- type Mergerdeprecated
- type Message
- type ReflectionProto
- type RequestMessageSupplierdeprecated
- type RequestParser
- type RequestSupplier
- type RequiredNotSetError
- type ServiceInfo
- type TextMarshaler
- type Unmarshalerdeprecated
Constants ¶
const ( // FormatJSON specifies input data in JSON format. Multiple request values // may be concatenated (messages with a JSON representation other than // object must be separated by whitespace, such as a newline) FormatJSON = Format("json") // FormatText specifies input data must be in the protobuf text format. // Multiple request values must be separated by the "record separator" // ASCII character: 0x1E. The stream should not end in a record separator. // If it does, it will be interpreted as a final, blank message after the // separator. FormatText = Format("text") )
const ( ProtoPackageIsVersion1 = true ProtoPackageIsVersion2 = true ProtoPackageIsVersion3 = true ProtoPackageIsVersion4 = true )
const ( KindPackage = ElementKind(iota) + 1 KindImport KindOption KindField KindMessage KindEnum KindService KindExtensionRange KindExtension KindReservedRange KindReservedName KindEnumValue KindMethod )
Variables ¶
var ErrReflectionNotSupported = errors.New("server does not support the reflection API")
ErrReflectionNotSupported is returned by DescriptorSource operations that rely on interacting with the reflection service when the source does not actually expose the reflection service. When this occurs, an alternate source (like file descriptor sets) must be used.
var ( MethodMap = map[string]string{ http.MethodGet: http.MethodGet, http.MethodHead: http.MethodHead, http.MethodPost: http.MethodPost, http.MethodPut: http.MethodPut, http.MethodPatch: http.MethodPatch, http.MethodDelete: http.MethodDelete, http.MethodConnect: http.MethodConnect, http.MethodOptions: http.MethodOptions, http.MethodTrace: http.MethodTrace, } )
Functions ¶
func AnyResolverFromDescriptorSource ¶
func AnyResolverFromDescriptorSource(source DescriptorSource) jsonpb.AnyResolver
AnyResolverFromDescriptorSource returns an AnyResolver that will search for types using the given descriptor source.
func AnyResolverFromDescriptorSourceWithFallback ¶
func AnyResolverFromDescriptorSourceWithFallback(source DescriptorSource) jsonpb.AnyResolver
AnyResolverFromDescriptorSourceWithFallback returns an AnyResolver that will search for types using the given descriptor source and then fallback to a special message if the type is not found. The fallback type will render to JSON with a "@type" property, just like an Any message, but also with a custom "@value" property that includes the binary encoded payload.
func BlockingDial ¶
func BlockingDial(ctx context.Context, network, address string, creds credentials.TransportCredentials, opts ...grpc.DialOption) (*grpc.ClientConn, error)
BlockingDial is a helper method to dial the given address, using optional TLS credentials, and blocking until the returned connection is ready. If the given credentials are nil, the connection will be insecure (plain-text).
func ClientTLSConfig ¶
func ClientTLSConfig(insecureSkipVerify bool, cacertFile, clientCertFile, clientKeyFile string) (*tls.Config, error)
ClientTLSConfig builds transport-layer config for a gRPC client using the given properties. If cacertFile is blank, only standard trusted certs are used to verify the server certs. If clientCertFile is blank, the client will not use a client certificate. If clientCertFile is not blank then clientKeyFile must not be blank.
func ClientTransportCredentials
deprecated
func ClientTransportCredentials(insecureSkipVerify bool, cacertFile, clientCertFile, clientKeyFile string) (credentials.TransportCredentials, error)
ClientTransportCredentials is a helper function that constructs a TLS config with the given properties (see ClientTLSConfig) and then constructs and returns gRPC transport credentials using that config.
Deprecated: Use grpcurl.ClientTLSConfig and credentials.NewTLS instead.
func CompactText ¶
CompactText writes the compact proto text format of m to w.
func CompactTextString ¶
CompactTextString returns a compact proto text formatted string of m.
func EnsureExtensions ¶
func EnsureExtensions(source DescriptorSource, msg proto.Message) proto.Message
EnsureExtensions uses the given descriptor source to download extensions for the given message. It returns a copy of the given message, but as a dynamic message that knows about all extensions known to the given descriptor source.
func Equal ¶
Equal reports whether two messages are equal. If two messages marshal to the same bytes under deterministic serialization, then Equal is guaranteed to report true.
Two messages are equal if they are the same protobuf message type, have the same set of populated known and extension field values, and the same set of unknown fields values.
Scalar values are compared with the equivalent of the == operator in Go, except bytes values which are compared using bytes.Equal and floating point values which specially treat NaNs as equal. Message values are compared by recursively calling Equal. Lists are equal if each element value is also equal. Maps are equal if they have the same set of keys, where the pair of values for each key is also equal.
func ExpandHeaders ¶
ExpandHeaders expands environment variables contained in the header string. If no corresponding environment variable is found an error is returned. TODO: Add escaping for `${`
func GetAllFiles ¶
func GetAllFiles(source DescriptorSource) ([]*desc.FileDescriptor, error)
GetAllFiles uses the given descriptor source to return a list of file descriptors.
func GetDescriptorText ¶
func GetDescriptorText(dsc desc.Descriptor, _ DescriptorSource) (string, error)
GetDescriptorText returns a string representation of the given descriptor. This returns a snippet of proto source that describes the given element.
func InvokeRPC ¶
func InvokeRPC(ctx context.Context, source DescriptorSource, ch grpcdynamic.Channel, methodName string, headers []string, handler InvocationEventHandler, requestData RequestSupplier) error
InvokeRPC uses the given gRPC channel to invoke the given method. The given descriptor source is used to determine the type of method and the type of request and response message. The given headers are sent as request metadata. Methods on the given event handler are called as the invocation proceeds.
The given requestData function supplies the actual data to send. It should return io.EOF when there is no more request data. If the method being invoked is a unary or server-streaming RPC (e.g. exactly one request message) and there is no request data (e.g. the first invocation of the function returns io.EOF), then an empty request message is sent.
If the requestData function and the given event handler coordinate or share any state, they should be thread-safe. This is because the requestData function may be called from a different goroutine than the one invoking event callbacks. (This only happens for bi-directional streaming RPCs, where one goroutine sends request messages and another consumes the response messages).
func InvokeRpc
deprecated
func InvokeRpc(ctx context.Context, source DescriptorSource, cc *grpc.ClientConn, methodName string, headers []string, handler InvocationEventHandler, requestData RequestMessageSupplier) error
InvokeRpc uses the given gRPC connection to invoke the given method. This function is deprecated and will be removed in a future release. It just delegates to the similarly named InvokeRPC method, whose signature is only slightly different.
Deprecated: use InvokeRPC instead.
func ListMethods ¶
func ListMethods(source DescriptorSource, serviceName string) ([]string, error)
ListMethods uses the given descriptor source to return a sorted list of method names for the specified fully-qualified service name.
func ListServiceMethod ¶
func ListServiceMethod(ctx context.Context, address string, headerList ...http.Header) (annotation map[string]*Annotation, err error)
ListServiceMethod list all service method
func ListServices ¶
func ListServices(source DescriptorSource) ([]string, error)
ListServices uses the given descriptor source to return a sorted list of fully-qualified service names.
func MakeTemplate ¶
func MakeTemplate(md *desc.MessageDescriptor) proto.Message
MakeTemplate returns a message instance for the given descriptor that is a suitable template for creating an instance of that message in JSON. In particular, it ensures that any repeated fields (which include map fields) are not empty, so they will render with a single element (to show the types and optionally nested fields). It also ensures that nested messages are not nil by setting them to a message that is also fleshed out as a template message.
func MarshalText ¶
MarshalText writes the proto text format of m to w.
func MarshalTextString ¶
MarshalTextString returns a proto text formatted string of m.
func Merge ¶
func Merge(dst, src Message)
Merge merges src into dst, which must be messages of the same type.
Populated scalar fields in src are copied to dst, while populated singular messages in src are merged into dst by recursively calling Merge. The elements of every list field in src is appended to the corresponded list fields in dst. The entries of every map field in src is copied into the corresponding map field in dst, possibly replacing existing entries. The unknown fields of src are appended to the unknown fields of dst.
func MessageReflect ¶
func MessageReflect(m Message) protoreflect.Message
MessageReflect returns a reflective view for a message. It returns nil if m is nil.
func MessageV1 ¶
func MessageV1(m GeneratedMessage) protoiface.MessageV1
MessageV1 converts either a v1 or v2 message to a v1 message. It returns nil if m is nil.
func MessageV2 ¶
func MessageV2(m GeneratedMessage) protoV2.Message
MessageV2 converts either a v1 or v2 message to a v2 message. It returns nil if m is nil.
func MetadataFromHeaders ¶
MetadataFromHeaders converts a list of header strings (each string in "Header-Name: Header-Value" form) into metadata. If a string has a header name without a value (e.g. does not contain a colon), the value is assumed to be blank. Binary headers (those whose names end in "-bin") should be base64-encoded. But if they cannot be base64-decoded, they will be assumed to be in raw form and used as is.
func MetadataToString ¶
MetadataToString returns a string representation of the given metadata, for displaying to users.
func PrintStatus ¶
PrintStatus prints details about the given status to the given writer. The given formatter is used to print any detail messages that may be included in the status. If the given status has a code of OK, "OK" is printed and that is all. Otherwise, "ERROR:" is printed along with a line showing the code, one showing the message string, and each detail message if any are present. The detail messages will be printed as proto text format or JSON, depending on the given formatter.
func RequestParserAndFormatter ¶
func RequestParserAndFormatter(format Format, descSource DescriptorSource, in io.Reader, opts FormatOptions) (RequestParser, Formatter, error)
RequestParserAndFormatter returns a request parser and formatter for the given format. The given descriptor source may be used for parsing message data (if needed by the format). It accepts a set of options. The field EmitJSONDefaultFields and IncludeTextSeparator are options for JSON and protobuf text formats, respectively. The AllowUnknownFields field is a JSON-only format flag. Requests will be parsed from the given in.
func RequestParserAndFormatterFor ¶
func RequestParserAndFormatterFor(format Format, descSource DescriptorSource, emitJSONDefaultFields, includeTextSeparator bool, in io.Reader) (RequestParser, Formatter, error)
RequestParserAndFormatterFor returns a request parser and formatter for the given format. The given descriptor source may be used for parsing message data (if needed by the format). The flags emitJSONDefaultFields and includeTextSeparator are options for JSON and protobuf text formats, respectively. Requests will be parsed from the given in. This function is deprecated. Please use RequestParserAndFormatter instead. DEPRECATED
func ServerTransportCredentials ¶
func ServerTransportCredentials(cacertFile, serverCertFile, serverKeyFile string, requireClientCerts bool) (credentials.TransportCredentials, error)
ServerTransportCredentials builds transport credentials for a gRPC server using the given properties. If cacertFile is blank, the server will not request client certs unless requireClientCerts is true. When requireClientCerts is false and cacertFile is not blank, the server will verify client certs when presented, but will not require client certs. The serverCertFile and serverKeyFile must both not be blank.
func WriteProtoset ¶
func WriteProtoset(out io.Writer, descSource DescriptorSource, symbols ...string) error
WriteProtoset will use the given descriptor source to resolve all of the given symbols and write a proto file descriptor set with their definitions to the given output. The output will include descriptors for all files in which the symbols are defined as well as their transitive dependencies.
Types ¶
type Annotation ¶
type CommentType ¶
type CommentType int
CommentType is a kind of comments in a proto source file. This can be used as a bitmask.
const ( // CommentsDetached refers to comments that are not "attached" to any // source element. They are attributed to the subsequent element in the // file as "detached" comments. CommentsDetached CommentType = 1 << iota // CommentsTrailing refers to a comment block immediately following an // element in the source file. If another element immediately follows // the trailing comment, it is instead considered a leading comment for // that subsequent element. CommentsTrailing // CommentsLeading refers to a comment block immediately preceding an // element in the source file. For high-level elements (those that have // their own descriptor), these are used as doc comments for that element. CommentsLeading // CommentsTokens refers to any comments (leading, trailing, or detached) // on low-level elements in the file. "High-level" elements have their own // descriptors, e.g. messages, enums, fields, services, and methods. But // comments can appear anywhere (such as around identifiers and keywords, // sprinkled inside the declarations of a high-level element). This class // of comments are for those extra comments sprinkled into the file. CommentsTokens // CommentsNonDoc refers to comments that are *not* doc comments. This is a // bitwise union of everything other than CommentsLeading. If you configure // a printer to omit this, only doc comments on descriptor elements will be // included in the printed output. CommentsNonDoc = CommentsDetached | CommentsTrailing | CommentsTokens // CommentsAll indicates all kinds of comments. If you configure a printer // to omit this, no comments will appear in the printed output, even if the // input descriptors had source info and comments. CommentsAll = -1 )
type DefaultEventHandler ¶
type DefaultEventHandler struct { Out io.Writer Formatter Formatter // 0 = default // 1 = verbose // 2 = very verbose VerbosityLevel int // NumResponses is the number of responses that have been received. NumResponses int // Status is the status that was received at the end of an RPC. It is // nil if the RPC is still in progress. Status *status.Status }
DefaultEventHandler logs events to a writer. This is not thread-safe, but is safe for use with InvokeRPC as long as NumResponses and Status are not read until the call to InvokeRPC completes.
func NewDefaultEventHandler
deprecated
func NewDefaultEventHandler(out io.Writer, descSource DescriptorSource, formatter Formatter, verbose bool) *DefaultEventHandler
NewDefaultEventHandler returns an InvocationEventHandler that logs events to the given output. If verbose is true, all events are logged. Otherwise, only response messages are logged.
Deprecated: NewDefaultEventHandler exists for compatibility. It doesn't allow fine control over the `VerbosityLevel` and provides only 0 and 1 options (which corresponds to the `verbose` argument). Use DefaultEventHandler{} initializer directly.
func (*DefaultEventHandler) OnReceiveHeaders ¶
func (h *DefaultEventHandler) OnReceiveHeaders(md metadata.MD)
func (*DefaultEventHandler) OnReceiveResponse ¶
func (h *DefaultEventHandler) OnReceiveResponse(resp proto.Message)
func (*DefaultEventHandler) OnReceiveTrailers ¶
func (h *DefaultEventHandler) OnReceiveTrailers(stat *status.Status, md metadata.MD)
func (*DefaultEventHandler) OnResolveMethod ¶
func (h *DefaultEventHandler) OnResolveMethod(md *desc.MethodDescriptor)
func (*DefaultEventHandler) OnSendHeaders ¶
func (h *DefaultEventHandler) OnSendHeaders(md metadata.MD)
type DescriptorSource ¶
type DescriptorSource interface { // ListServices returns a list of fully-qualified service names. It will be all services in a set of // descriptor files or the set of all services exposed by a gRPC server. ListServices() ([]string, error) // FindSymbol returns a descriptor for the given fully-qualified symbol name. FindSymbol(fullyQualifiedName string) (desc.Descriptor, error) // AllExtensionsForType returns all known extension fields that extend the given message type name. AllExtensionsForType(typeName string) ([]*desc.FieldDescriptor, error) }
DescriptorSource is a source of protobuf descriptor information. It can be backed by a FileDescriptorSet proto (like a file generated by protoc) or a remote server that supports the reflection API.
func DescriptorSourceFromFileDescriptorSet ¶
func DescriptorSourceFromFileDescriptorSet(files *descriptorpb.FileDescriptorSet) (DescriptorSource, error)
DescriptorSourceFromFileDescriptorSet creates a DescriptorSource that is backed by the FileDescriptorSet.
func DescriptorSourceFromFileDescriptors ¶
func DescriptorSourceFromFileDescriptors(files ...*desc.FileDescriptor) (DescriptorSource, error)
DescriptorSourceFromFileDescriptors creates a DescriptorSource that is backed by the given file descriptors
func DescriptorSourceFromProtoFiles ¶
func DescriptorSourceFromProtoFiles(importPaths []string, fileNames ...string) (DescriptorSource, error)
DescriptorSourceFromProtoFiles creates a DescriptorSource that is backed by the named files, whose contents are Protocol Buffer source files. The given importPaths are used to locate any imported files.
func DescriptorSourceFromProtoSets ¶
func DescriptorSourceFromProtoSets(fileNames ...string) (DescriptorSource, error)
DescriptorSourceFromProtoSets creates a DescriptorSource that is backed by the named files, whose contents are encoded FileDescriptorSet protos.
func DescriptorSourceFromServer ¶
func DescriptorSourceFromServer(_ context.Context, refClient *grpcreflect.Client) DescriptorSource
DescriptorSourceFromServer creates a DescriptorSource that uses the given gRPC reflection client to interrogate a server for descriptor information. If the server does not support the reflection API then the various DescriptorSource methods will return ErrReflectionNotSupported
func GetDescSource ¶
func GetDescSource(ctx context.Context, address string, headerList ...http.Header) (DescriptorSource, error)
GetDescSource is a function that returns a string describing the source of a
type Element ¶
type Element interface { // Kind returns the kind of the element. The kind determines which other // methods are applicable. Kind() ElementKind // Name returns the element name. This is NOT applicable to syntax, // extension range, and reserved range kinds and will return the empty // string for these kinds. For custom options, this will be the // fully-qualified name of the corresponding extension. Name() string // Number returns the element number. This is only applicable to field, // extension, and enum value kinds and will return zero for all other kinds. Number() int32 // NumberRange returns the range of numbers/tags for the element. This is // only applicable to extension ranges and reserved ranges and will return // (0, 0) for all other kinds. NumberRange() (int32, int32) // Extendee is the extended message for the extension element. Elements // other than extensions will return the empty string. Extendee() string // IsCustomOption returns true if the element is a custom option. If it is // not (including if the element kind is not option) then this method will // return false. IsCustomOption() bool }
Element represents an element in a proto descriptor that can be printed. This interface is primarily used to allow users of this package to define custom sort orders for the printed output. The methods of this interface represent the values that can be used for ordering elements.
type ElementKind ¶
type ElementKind int
ElementKind is an enumeration of the types of elements in a protobuf file descriptor. This can be used by custom sort functions, for printing a file using a custom ordering of elements.
type FormatOptions ¶
type FormatOptions struct { // EmitJSONDefaultFields flag, when true, includes empty/default values in the output. // FormatJSON only flag. EmitJSONDefaultFields bool // AllowUnknownFields is an option for the parser. When true, // it accepts input which includes unknown fields. These unknown fields // are skipped instead of returning an error. // FormatJSON only flag. AllowUnknownFields bool // IncludeTextSeparator is true then, when invoked to format multiple messages, // all messages after the first one will be prefixed with the // ASCII 'Record Separator' character (0x1E). // It might be useful when the output is piped to another grpcurl process. // FormatText only flag. IncludeTextSeparator bool }
FormatOptions is a set of flags that are passed to a JSON or text formatter.
type Formatter ¶
Formatter translates messages into string representations.
func NewJSONFormatter ¶
func NewJSONFormatter(emitDefaults bool, resolver jsonpb.AnyResolver) Formatter
NewJSONFormatter returns a formatter that returns JSON strings. The JSON will include empty/default values (instead of just omitted them) if emitDefaults is true. The given resolver is used to assist with encoding of google.protobuf.Any messages.
func NewTextFormatter ¶
NewTextFormatter returns a formatter that returns strings in the protobuf text format. If includeSeparator is true then, when invoked to format multiple messages, all messages after the first one will be prefixed with the ASCII 'Record Separator' character (0x1E).
type GeneratedEnum ¶
type GeneratedEnum interface{}
GeneratedEnum is any enum type generated by protoc-gen-go which is a named int32 kind. This type exists for documentation purposes.
type GeneratedMessage ¶
type GeneratedMessage interface{}
GeneratedMessage is any message type generated by protoc-gen-go which is a pointer to a named struct kind. This type exists for documentation purposes.
type InvocationEventHandler ¶
type InvocationEventHandler interface { // OnResolveMethod is called with a descriptor of the method that is being invoked. OnResolveMethod(*desc.MethodDescriptor) // OnSendHeaders is called with the request metadata that is being sent. OnSendHeaders(metadata.MD) // OnReceiveHeaders is called when response headers have been received. OnReceiveHeaders(metadata.MD) // OnReceiveResponse is called for each response message received. OnReceiveResponse(proto.Message) // OnReceiveTrailers is called when response trailers and final RPC status have been received. OnReceiveTrailers(*status.Status, metadata.MD) }
InvocationEventHandler is a bag of callbacks for handling events that occur in the course of invoking an RPC. The handler also provides request data that is sent. The callbacks are generally called in the order they are listed below.
type Marshaler
deprecated
type Marshaler interface { // Marshal formats the encoded bytes of the message. // It should be deterministic and emit valid protobuf wire data. // The caller takes ownership of the returned buffer. Marshal() ([]byte, error) }
Marshaler is implemented by messages that can marshal themselves. This interface is used by the following functions: Size, Marshal, Buffer.Marshal, and Buffer.EncodeMessage.
Deprecated: Do not implement.
type Merger
deprecated
type Merger interface { // Merge merges the contents of src into the receiver message. // It clones all data structures in src such that it aliases no mutable // memory referenced by src. Merge(src Message) }
Merger is implemented by messages that can merge themselves. This interface is used by the following functions: Clone and Merge.
Deprecated: Do not implement.
type Message ¶
type Message = protoiface.MessageV1
Message is a protocol buffer message.
This is the v1 version of the message interface and is marginally better than an empty interface as it lacks any method to programatically interact with the contents of the message.
A v2 message is declared in "google.golang.org/protobuf/proto".Message and exposes protobuf reflection as a first-class feature of the interface.
To convert a v1 message to a v2 message, use the MessageV2 function. To convert a v2 message to a v1 message, use the MessageV1 function.
type ReflectionProto ¶
type ReflectionProto struct { // If true, comments are rendered using "/*" style comments. Otherwise, they // are printed using "//" style line comments. PreferMultiLineStyleComments bool // If true, elements are sorted into a canonical order. // // The canonical order for elements in a file follows: // 1. Syntax // 2. Package // 3. Imports (sorted lexically) // 4. Options (sorted by name, standard options before custom options) // 5. Messages (sorted by name) // 6. Enums (sorted by name) // 7. Services (sorted by name) // 8. Extensions (grouped by extendee, sorted by extendee+tag) // // The canonical order of elements in a message follows: // 1. Options (sorted by name, standard options before custom options) // 2. Fields and One-Ofs (sorted by tag; one-ofs interleaved based on the // minimum tag therein) // 3. Nested Messages (sorted by name) // 4. Nested Enums (sorted by name) // 5. Extension ranges (sorted by starting tag number) // 6. Nested Extensions (grouped by extendee, sorted by extendee+tag) // 7. Reserved ranges (sorted by starting tag number) // 8. Reserved names (sorted lexically) // // Methods are sorted within a service by name and appear after any service // options (which are sorted by name, standard options before custom ones). // Enum values are sorted within an enum, first by numeric value then by // name, and also appear after any enum options. // // Options for fields, enum values, and extension ranges are sorted by name, // standard options before custom ones. SortElements bool // The "less" function used to sort elements when printing. It is given two // elements, a and b, and should return true if a is "less than" b. In this // case, "less than" means that element a should appear earlier in the file // than element b. // // If this field is nil, no custom sorting is done and the SortElements // field is consulted to decide how to order the output. If this field is // non-nil, the SortElements field is ignored and this function is called to // order elements. CustomSortFunction func(a, b Element) bool // The indentation used. Any characters other than spaces or tabs will be // replaced with spaces. If unset/empty, two spaces will be used. Indent string // If true, detached comments (between elements) will be ignored. // // Deprecated: Use OmitComments bitmask instead. OmitDetachedComments bool // A bitmask of comment types to omit. If unset, all comments will be // included. Use CommentsAll to not print any comments. OmitComments CommentType // If true, trailing comments that typically appear on the same line as an // element (option, field, enum value, method) will be printed on a separate // line instead. // // So, with this set, you'll get output like so: // // // leading comment for field // repeated string names = 1; // // trailing comment // // If left false, the printer will try to emit trailing comments on the same // line instead: // // // leading comment for field // repeated string names = 1; // trailing comment // // If the trailing comment has more than one line, it will automatically be // forced to the next line. TrailingCommentsOnSeparateLine bool // If true, the printed output will eschew any blank lines, which otherwise // appear between descriptor elements and comment blocks. Note that if // detached comments are being printed, this will cause them to be merged // into the subsequent leading comments. Similarly, any element trailing // comments will be merged into the subsequent leading comments. Compact bool // If true, all references to messages, extensions, and enums (such as in // options, field types, and method request and response types) will be // fully-qualified. When left unset, the referenced elements will contain // only as much qualifier as is required. // // For example, if a message is in the same package as the reference, the // simple name can be used. If a message shares some context with the // reference, only the unshared context needs to be included. For example: // // message Foo { // message Bar { // enum Baz { // ZERO = 0; // ONE = 1; // } // } // // // This field shares some context as the enum it references: they are // // both inside of the namespace Foo: // // field is "Foo.my_baz" // // enum is "Foo.Bar.Baz" // // So we only need to qualify the reference with the context that they // // do NOT have in common: // Bar.Baz my_baz = 1; // } // // When printing fully-qualified names, they will be preceded by a dot, to // avoid any ambiguity that they might be relative vs. fully-qualified. ForceFullyQualifiedNames bool // The number of options that trigger short options expressions to be // rendered using multiple lines. Short options expressions are those // found on fields and enum values, that use brackets ("[" and "]") and // comma-separated options. If more options than this are present, they // will be expanded to multiple lines (one option per line). // // If unset (e.g. if zero), a default threshold of 3 is used. ShortOptionsExpansionThresholdCount int // The length of printed options that trigger short options expressions to // be rendered using multiple lines. If the short options contain more than // one option and their printed length is longer than this threshold, they // will be expanded to multiple lines (one option per line). // // If unset (e.g. if zero), a default threshold of 50 is used. ShortOptionsExpansionThresholdLength int // The length of a printed option value message literal that triggers the // message literal to be rendered using multiple lines instead of using a // compact single-line form. The message must include at least two fields // or contain a field that is a nested message to be expanded. // // This value is further used to decide when to expand individual field // values that are nested message literals or array literals (for repeated // fields). // // If unset (e.g. if zero), a default threshold of 50 is used. MessageLiteralExpansionThresholdLength int // Syntax proto version Syntax string // Package proto package Package string // Dependency dep Dependency []string // Comment Comment []string // FileOptions FileOptions []option // FileMessageDescriptor FileMessageDescriptor []*desc.MessageDescriptor // FileEnumDescriptor FileEnumDescriptor []*desc.EnumDescriptor // FileServiceInfo FileServiceInfo []*ServiceInfo // FileFieldDescriptor FileFieldDescriptor []*desc.FieldDescriptor // FileExtensions FileExtensions extensions // MethodOptions MethodOptions map[*desc.MethodDescriptor][]option }
ReflectionProto knows how to format file descriptors as proto source code. Its fields provide some control over how the resulting source file is constructed and formatted.
func ProtoInfoDesc ¶
func ProtoInfoDesc(dsc desc.Descriptor) *ReflectionProto
ProtoInfoDesc desc proto info
type RequestMessageSupplier
deprecated
RequestMessageSupplier is a function that is called to retrieve request messages for a GRPC operation. This type is deprecated and will be removed in a future release.
Deprecated: This is only used with the deprecated InvokeRpc. Instead, use RequestSupplier with InvokeRPC.
type RequestParser ¶
type RequestParser interface { // Next parses input data into the given request message. If called after // input is exhausted, it returns io.EOF. If the caller re-uses the same // instance in multiple calls to Next, it should call msg.Reset() in between // each call. Next(msg proto.Message) error // NumRequests returns the number of messages that have been parsed and // returned by a call to Next. NumRequests() int }
RequestParser processes input into messages.
func NewJSONRequestParser ¶
func NewJSONRequestParser(in io.Reader, resolver jsonpb.AnyResolver) RequestParser
NewJSONRequestParser returns a RequestParser that reads data in JSON format from the given reader. The given resolver is used to assist with decoding of google.protobuf.Any messages.
Input data that contains more than one message should just include all messages concatenated (though whitespace is necessary to separate some kinds of values in JSON).
If the given reader has no data, the returned parser will return io.EOF on the very first call.
func NewJSONRequestParserWithUnmarshaler ¶
func NewJSONRequestParserWithUnmarshaler(in io.Reader, unmarshaler jsonpb.Unmarshaler) RequestParser
NewJSONRequestParserWithUnmarshaler is like NewJSONRequestParser but accepts a protobuf jsonpb.Unmarshaler instead of jsonpb.AnyResolver.
func NewTextRequestParser ¶
func NewTextRequestParser(in io.Reader) RequestParser
NewTextRequestParser returns a RequestParser that reads data in the protobuf text format from the given reader.
Input data that contains more than one message should include an ASCII 'Record Separator' character (0x1E) between each message.
Empty text is a valid text format and represents an empty message. So if the given reader has no data, the returned parser will yield an empty message for the first call to Next and then return io.EOF thereafter. This also means that if the input data ends with a record separator, then a final empty message will be parsed *after* the separator.
type RequestSupplier ¶
RequestSupplier is a function that is called to populate messages for a gRPC operation. The function should populate the given message or return a non-nil error. If the supplier has no more messages, it should return io.EOF. When it returns io.EOF, it should not in any way modify the given message argument.
type RequiredNotSetError ¶
type RequiredNotSetError struct {
// contains filtered or unexported fields
}
RequiredNotSetError is an error type returned when marshaling or unmarshaling a message with missing required fields.
func (*RequiredNotSetError) Error ¶
func (e *RequiredNotSetError) Error() string
func (*RequiredNotSetError) RequiredNotSet ¶
func (e *RequiredNotSetError) RequiredNotSet() bool
type ServiceInfo ¶
type ServiceInfo struct { ServiceDescriptor *desc.ServiceDescriptor MethodDescriptor []*desc.MethodDescriptor Options []option }
ServiceInfo rpc info
type TextMarshaler ¶
type TextMarshaler struct { Compact bool // use compact text format (one line) ExpandAny bool // expand google.protobuf.Any messages of known types }
TextMarshaler is a configurable text format marshaler.
func (*TextMarshaler) Marshal ¶
func (tm *TextMarshaler) Marshal(w io.Writer, m Message) error
Marshal writes the proto text format of m to w.
func (*TextMarshaler) Text ¶
func (tm *TextMarshaler) Text(m Message) string
Text returns a proto text formatted string of m.
type Unmarshaler
deprecated
type Unmarshaler interface { // Unmarshal parses the encoded bytes of the protobuf wire input. // The provided buffer is only valid for during method call. // It should not reset the receiver message. Unmarshal([]byte) error }
Unmarshaler is implemented by messages that can unmarshal themselves. This interface is used by the following functions: Unmarshal, UnmarshalMerge, Buffer.Unmarshal, Buffer.DecodeMessage, and Buffer.DecodeGroup.
Deprecated: Do not implement.