descriptor

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package descriptor holds descriptors of gRPC services, messages and enums that can be used to generate gRPC Rest Gateway Code, Open API documentation and other things.

Index

Constants

View Source
const (
	PathParameterSeparatorCSV = iota
	PathParameterSeparatorPipes
	PathParameterSeparatorSSV
	PathParameterSeparatorTSV
)

Variables

This section is empty.

Functions

func IsWellKnownType

func IsWellKnownType(typeName string) bool

IsWellKnownType returns true if the provided fully qualified type name is considered 'well-known'.

Types

type Binding

type Binding struct {
	// Method is the method which the endpoint is bound to.
	Method *Method
	// Index is a zero-origin index of the binding in the target method
	Index int
	// PathTemplate is path template where this method is mapped to.
	PathTemplate httprule.Template
	// HTTPMethod is the HTTP method which this method is mapped to.
	HTTPMethod string
	// PathParameters is the list of parameters provided in HTTP request paths.
	PathParameters []Parameter
	// QueryParameterCustomization holds any customization for the way query parameters are handled.
	QueryParameterCustomization QueryParameterCustomization
	// Body describes parameters provided in HTTP request body.
	Body *Body
	// ResponseBody describes field in response struct to marshal in HTTP response body.
	ResponseBody *Body
	// QueryParameters is the full list of query parameters.
	QueryParameters []QueryParameter
	// StreamConfig holds streaming API configurations.
	StreamConfig StreamConfig
}

Binding describes how an HTTP endpoint is bound to a gRPC method.

func (*Binding) HasAnyStreamingMethod

func (b *Binding) HasAnyStreamingMethod() bool

HasAnyStreamingMethod returns whether or not this binding supports any streaming method. (SSE, Websocket, Chunked Transfer).

func (*Binding) HasQueryParameters

func (b *Binding) HasQueryParameters() bool

HasQueryParameters indicates whether or not this binding reads any query parameters.

func (*Binding) NeedsChunkedTransfer

func (b *Binding) NeedsChunkedTransfer() bool

NeedsChunkedTransfer returns whether or not chunked transfer is needed.

func (*Binding) NeedsSSE

func (b *Binding) NeedsSSE() bool

NeedsSSE returns whether or not websocket binding is needed.

func (*Binding) NeedsWebsocket

func (b *Binding) NeedsWebsocket() bool

NeedsWebsocket returns whether or not websocket binding is needed.

func (*Binding) QueryParameterFilter

func (b *Binding) QueryParameterFilter() *trie.Node

QueryParameterFilter returns a trie that filters out field paths that are not available to be used as query parameter.

type Body

type Body struct {
	// FieldPath is a path to a proto field which this parameter is mapped to.
	FieldPath FieldPath
}

Body describes a http (request|response) body to be sent to the (method|client). This is used in body and response_body options in google.api.HttpRule

func (Body) AssignableExpr

func (b Body) AssignableExpr(msgExpr string, currentPackage string) string

AssignableExpr returns an assignable expression in Go to be used to initialize method request object. It starts with "msgExpr", which is the go expression of the method request object.

func (Body) AssignableExprPrep

func (b Body) AssignableExprPrep(msgExpr string, currentPackage string) string

AssignableExprPrep returns preparatory statements for an assignable expression to initialize the method request object.

type Enum

type Enum struct {
	*descriptorpb.EnumDescriptorProto
	// File is the file where the enum is defined
	File *File
	// Outers is a list of outer messages if this enum is a nested type.
	Outers []string
	// Index is a enum index value.
	Index int
	// ForcePrefixedName when set to true, prefixes a type with a package prefix.
	ForcePrefixedName bool
	// contains filtered or unexported fields
}

Enum describes a protocol buffer enum types.

func (*Enum) FQEN

func (e *Enum) FQEN() string

FQEN returns a fully qualified enum name of this enum.

func (*Enum) GoType

func (e *Enum) GoType(currentPackage string) string

GoType returns a go type name for the enum type. It prefixes the type name with the package alias if its belonging package is not "currentPackage".

func (*Enum) Path

func (e *Enum) Path() dotpath.Instance

type Field

type Field struct {
	*descriptorpb.FieldDescriptorProto
	// Message is the message type which this field belongs to.
	Message *Message
	// ForcePrefixedName when set to true, prefixes a type with a package prefix.
	ForcePrefixedName bool
	// Index is the index of the field in the message proto descriptor.
	Index int
	// contains filtered or unexported fields
}

Field wraps descriptorpb.FieldDescriptorProto for richer features.

func (*Field) FQFN

func (f *Field) FQFN() string

FQFN returns a fully qualified field name of this field.

func (*Field) HasRepeatedLabel

func (f *Field) HasRepeatedLabel() bool

HasRepeatedLabel returns whether or not this field has repeated label on it.

NOTE: This is not an indication that this field is necessarily an array since the underlying type can be a map entry.

func (*Field) IsScalarType

func (f *Field) IsScalarType() bool

IsScalarType returns whether or not this field points to a scalar type.

func (*Field) Path

func (f *Field) Path() dotpath.Instance

type FieldPath

type FieldPath []FieldPathComponent

FieldPath is a path to a field from a request message.

func (FieldPath) AssignableExpr

func (p FieldPath) AssignableExpr(msgExpr string, currentPackage string) string

AssignableExpr is an assignable expression in Go to be used to assign a value to the target field. It starts with "msgExpr", which is the go expression of the method request object. Before using such an expression the prep statements must be emitted first, in case the field path includes a oneof. See FieldPath.AssignableExprPrep.

func (FieldPath) AssignableExprPrep

func (p FieldPath) AssignableExprPrep(msgExpr string, currentPackage string) string

AssignableExprPrep returns preparation statements for an assignable expression to assign a value to the target field. The Go expression of the method request object is "msgExpr". This is only needed for field paths that contain oneofs. Otherwise, an empty string is returned.

func (FieldPath) IsNestedProto3

func (p FieldPath) IsNestedProto3() bool

IsNestedProto3 indicates whether the FieldPath is a nested Proto3 path.

func (FieldPath) IsOptionalProto3

func (p FieldPath) IsOptionalProto3() bool

IsOptionalProto3 indicates whether the FieldPath is a proto3 optional field.

func (FieldPath) String

func (p FieldPath) String() string

String returns a string representation of the field path.

func (FieldPath) Target

func (p FieldPath) Target() *Field

type FieldPathComponent

type FieldPathComponent struct {
	// Name is a name of the proto field which this component corresponds to.
	Name string
	// Target is the proto field which this component corresponds to.
	Target *Field
}

FieldPathComponent is a path component in FieldPath

func (FieldPathComponent) AssignableExpr

func (c FieldPathComponent) AssignableExpr() string

AssignableExpr returns an assignable expression in go for this field.

func (FieldPathComponent) ValueExpr

func (c FieldPathComponent) ValueExpr() string

ValueExpr returns an expression in go for this field.

type File

type File struct {
	*descriptorpb.FileDescriptorProto
	// GoPkg is the go package of the go file generated from this file.
	GoPkg GoPackage
	// GeneratedFilenamePrefix is used to construct filenames for generated
	// files associated with this source file.
	//
	// For example, the source file "dir/foo.proto" might have a filename prefix
	// of "dir/foo". Appending ".pb.go" produces an output file of "dir/foo.pb.go".
	GeneratedFilenamePrefix string
	// Messages is the list of messages defined in this file.
	Messages []*Message
	// Enums is the list of enums defined in this file.
	Enums []*Enum
	// Services is the list of services defined in this file.
	Services []*Service
}

File wraps descriptorpb.FileDescriptorProto for richer features.

func (*File) Pkg

func (f *File) Pkg() string

Pkg returns package name or alias if it's present

type GatewayFileLoadOptions

type GatewayFileLoadOptions struct {
	// GlobalGatewayConfigFile points to the global gateway config file.
	GlobalGatewayConfigFile string

	// FilePattern holds the file pattern for loading gateway config files.
	//
	// This pattern must not include the extension and the priority is yaml, yml and finally json.
	FilePattern string
}

GatewayFileLoadOptions holds the gateway config file loading options.

type GoPackage

type GoPackage struct {
	// Path is the package path to the package.
	Path string
	// Name is the package name of the package
	Name string
	// Alias is an alias of the package unique within the current invocation of gRPC-Gateway generator.
	Alias string
}

GoPackage represents a golang package.

func (GoPackage) Standard

func (p GoPackage) Standard() bool

Standard returns whether the import is a golang standard package.

func (GoPackage) String

func (p GoPackage) String() string

String returns a string representation of this package in the form of import line in golang.

type Message

type Message struct {
	*descriptorpb.DescriptorProto
	// File is the file where the message is defined.
	File *File
	// Outers is a list of outer messages if this message is a nested type.
	Outers []string
	// Fields is a list of message fields.
	Fields []*Field
	// Index is proto path index of this message in File.
	Index int
	// ForcePrefixedName when set to true, prefixes a type with a package prefix.
	ForcePrefixedName bool
	// contains filtered or unexported fields
}

Message describes a protocol buffer message types.

func (*Message) FQMN

func (m *Message) FQMN() string

FQMN returns a fully qualified message name of this message.

func (*Message) GoType

func (m *Message) GoType(currentPackage string) string

GoType returns a go type name for the message type. It prefixes the type name with the package alias if its belonging package is not "currentPackage".

func (*Message) IsMapEntry

func (m *Message) IsMapEntry() bool

func (*Message) Path

func (m *Message) Path() dotpath.Instance

type Method

type Method struct {
	*descriptorpb.MethodDescriptorProto
	// Service is the service which this method belongs to.
	Service *Service
	// RequestType is the message type of requests to this method.
	RequestType *Message
	// ResponseType is the message type of responses from this method.
	ResponseType *Message
	// Bindings are the HTTP endpoint bindings.
	Bindings []*Binding
	// Index is the index of the method in the service.
	Index int
	// contains filtered or unexported fields
}

Method wraps descriptorpb.MethodDescriptorProto for richer features.

func (*Method) FQMN

func (m *Method) FQMN() string

FQMN returns a fully qualified rpc method name of this method.

func (*Method) Path

func (m *Method) Path() dotpath.Instance

type Parameter

type Parameter struct {
	// FieldPath is a path to a proto field which this parameter is mapped to.
	FieldPath
	// Target is the proto field which this parameter is mapped to.
	Target *Field
	// Method is the method which this parameter is used for.
	Method *Method
}

Parameter is a parameter provided in http requests

func (Parameter) ConvertFuncExpr

func (p Parameter) ConvertFuncExpr() (string, error)

ConvertFuncExpr returns a go expression of a converter function. The converter function converts a string into a value for the parameter.

func (Parameter) IsEnum

func (p Parameter) IsEnum() bool

IsEnum returns true if the field is an enum type, otherwise false is returned.

func (Parameter) IsProto2

func (p Parameter) IsProto2() bool

IsProto2 returns true if the field is proto2, otherwise false is returned.

func (Parameter) IsRepeated

func (p Parameter) IsRepeated() bool

IsRepeated returns true if the field is repeated, otherwise false is returned.

type PathParameterSeparator

type PathParameterSeparator uint8

func (PathParameterSeparator) Separator

func (p PathParameterSeparator) Separator() rune

func (*PathParameterSeparator) Set

func (p *PathParameterSeparator) Set(value string) error

func (PathParameterSeparator) String

func (p PathParameterSeparator) String() string

type QueryParamAlias

type QueryParamAlias struct {
	// Name is the name that will be read from the query parameters.
	Name string
	// CustomName indicates the name is a custom and user-specified name, not a generated name.
	CustomName bool
	// FieldPath is a path to a proto field which this parameter is mapped to.
	FieldPath FieldPath
}

QueryParamAlias describes a query parameter alias, used to set/rename query params.

type QueryParameter

type QueryParameter struct {
	// FieldPath is a path to a proto field which this parameter is mapped to.
	FieldPath

	// Name is the name of the query parameter.
	Name string

	// NameIsAlias indicates whether or not the name is a custom alias.
	NameIsAlias bool
}

QueryParameter describes a query paramter.

func (QueryParameter) String

func (q QueryParameter) String() string

func (QueryParameter) Target

func (q QueryParameter) Target() *Field

type QueryParameterCustomization

type QueryParameterCustomization struct {
	// IgnoredFields are the field paths that are ignored.
	IgnoredFields []FieldPath
	// Aliases are the query parameter aliases.
	Aliases []QueryParamAlias
	// DisableAutoDiscovery disables auto discovery of query parameters and only allows the explicit declerations.
	DisableAutoDiscovery bool
}

QueryParameterCustomization describes the way query parameters are to get parsed.

type Registry

type Registry struct {
	RegistryOptions
	// contains filtered or unexported fields
}

Registry is a registry of information extracted from pluginpb.CodeGeneratorRequest.

func NewRegistry

func NewRegistry(options RegistryOptions) *Registry

NewRegistry creates and initializes a new registry.

func (*Registry) Iterate

func (r *Registry) Iterate(cb func(fielPath string, protoFile *File) error) error

Iterate iterates over all processed files.

func (*Registry) LoadFromPlugin

func (r *Registry) LoadFromPlugin(gen *protogen.Plugin) error

LoadFromPlugin loads all messages and enums in all files and services in all files that need generation.

func (*Registry) LookupEnum

func (r *Registry) LookupEnum(location, name string) (*Enum, error)

LookupEnum looks up a enum type by "name". It tries to resolve "name" from "location" if "name" is a relative enum name.

func (*Registry) LookupFile

func (r *Registry) LookupFile(name string) (*File, error)

LookupFile looks up a file by name.

func (*Registry) LookupMessage

func (r *Registry) LookupMessage(location, name string) (*Message, error)

LookupMessage looks up a message type by "name". It tries to resolve "name" from "location" if "name" is a relative message name.

location must be a dot separated proto package to build a FQMN.

func (*Registry) ReserveGoPackageAlias

func (r *Registry) ReserveGoPackageAlias(alias, pkgPath string) bool

ReserveGoPackageAlias reserves the unique alias of go package. If succeeded, the alias will be never used for other packages in generated go files. If failed, the alias is already taken by another package, so you need to use another alias for the package in your go files.

func (*Registry) UnboundExternalHTTPSpecs

func (r *Registry) UnboundExternalHTTPSpecs() []httpspec.EndpointSpec

UnboundExternalHTTPSpecs returns the list of external HTTP specs which do not have a matching method in the registry.

type RegistryOptions

type RegistryOptions struct {
	// GatewayFileLoadOptions holds gateway config file loading options.
	GatewayFileLoadOptions GatewayFileLoadOptions

	// SearchPath is the directory that is used to look for gateway configuration files.
	//
	// this search path can be relative or absolute, if relative, it will be from the current working directory.
	SearchPath string

	// WarnOnUnboundMethods emits a warning message if an RPC method has no mapping.
	WarnOnUnboundMethods bool

	// GenerateUnboundMethods controls whether or not unannotated RPC methods should be created as part of the proxy.
	GenerateUnboundMethods bool

	// AllowDeleteBody indicates whether or not DELETE methods can have bodies.
	AllowDeleteBody bool

	// Standalone mode is to prepare for generation of Go files as a standalone package.
	Standalone bool
}

RegistryOptions holds all the options for the descriptor registry.

func DefaultRegistryOptions

func DefaultRegistryOptions() RegistryOptions

func (*RegistryOptions) AddFlags

func (r *RegistryOptions) AddFlags(flags *flag.FlagSet)

AddFlags adds command line flags to update this gateway loading options.

type ResponseFile

type ResponseFile struct {
	*pluginpb.CodeGeneratorResponse_File
	// GoPkg is the Go package of the generated file.
	GoPkg GoPackage
}

ResponseFile wraps pluginpb.CodeGeneratorResponse_File.

type Service

type Service struct {
	*descriptorpb.ServiceDescriptorProto
	// File is the file where this service is defined.
	File *File
	// Methods is the list of methods defined in this service.
	Methods []*Method
	// ForcePrefixedName when set to true, prefixes a type with a package prefix.
	ForcePrefixedName bool
	// Index is the index of the service in the proto file.
	Index int
	// contains filtered or unexported fields
}

Service wraps descriptorpb.ServiceDescriptorProto for richer features.

func (*Service) ClientConstructorName

func (s *Service) ClientConstructorName() string

ClientConstructorName returns name of the Client constructor with package prefix if needed

func (*Service) FQSN

func (s *Service) FQSN() string

FQSN returns the fully qualified service name of this service.

func (*Service) InstanceName

func (s *Service) InstanceName() string

InstanceName returns object name of the service with package prefix if needed

func (*Service) Path

func (s *Service) Path() dotpath.Instance

type StreamConfig

type StreamConfig struct {
	// AllowWebsocket indicates whether or not websocket is allowed.
	AllowWebsocket bool
	// AllowSSE indicates whether or not SSE is allowed.
	AllowSSE bool
	// AllowChunkedTransfer indicates whether or not chunked transfer encoding is allowed.
	AllowChunkedTransfer bool
}

StreamConfig includes directions on which streaming modes are enabled/disabled.

Jump to

Keyboard shortcuts

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