Documentation ¶
Overview ¶
Package descriptor provides the corresponding capabilities for parsing IDL.
Index ¶
- Constants
- type Desc
- type FbsAttrs
- type FbsFileDescriptor
- func (p *FbsFileDescriptor) GetDependencies() []Desc
- func (p *FbsFileDescriptor) GetFileOptions() FileOpt
- func (p *FbsFileDescriptor) GetFullyQualifiedName() string
- func (p *FbsFileDescriptor) GetMessageTypes() []MessageDesc
- func (p *FbsFileDescriptor) GetName() string
- func (p *FbsFileDescriptor) GetPackage() string
- func (p *FbsFileDescriptor) GetServices() []ServiceDesc
- type FbsMessageDescriptor
- type FbsMethodDescriptor
- func (p *FbsMethodDescriptor) GetInputType() MessageDesc
- func (p *FbsMethodDescriptor) GetName() string
- func (p *FbsMethodDescriptor) GetOutputType() MessageDesc
- func (p *FbsMethodDescriptor) GetSourceInfo() SourceInfo
- func (p *FbsMethodDescriptor) IsClientStreaming() bool
- func (p *FbsMethodDescriptor) IsServerStreaming() bool
- type FbsServiceDescriptor
- type FbsSourceInfo
- type FileDescriptor
- type FileOpt
- type ImportDesc
- type MessageDesc
- type MethodDesc
- type ProtoFileDescriptor
- func (p *ProtoFileDescriptor) GetDependencies() []Desc
- func (p *ProtoFileDescriptor) GetFileOptions() FileOpt
- func (p *ProtoFileDescriptor) GetFullyQualifiedName() string
- func (p *ProtoFileDescriptor) GetMessageTypes() []MessageDesc
- func (p *ProtoFileDescriptor) GetName() string
- func (p *ProtoFileDescriptor) GetPackage() string
- func (p *ProtoFileDescriptor) GetServices() []ServiceDesc
- type ProtoMessageDescriptor
- type ProtoMethodDescriptor
- func (p *ProtoMethodDescriptor) GetInputType() MessageDesc
- func (p *ProtoMethodDescriptor) GetName() string
- func (p *ProtoMethodDescriptor) GetOutputType() MessageDesc
- func (p *ProtoMethodDescriptor) GetSourceInfo() SourceInfo
- func (p *ProtoMethodDescriptor) IsClientStreaming() bool
- func (p *ProtoMethodDescriptor) IsServerStreaming() bool
- type ProtoServiceDescriptor
- type RESTfulAPIContent
- type RESTfulAPIDescriptor
- type RPCDescriptor
- type ServiceDesc
- type ServiceDescriptor
- type SourceInfo
- type SwaggerDescriptor
- type SwaggerParamDescriptor
Constants ¶
const GoPackage = "go_package"
GoPackage is the key's value of "go package" in file options.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Desc ¶
type Desc interface { // GetName returns the original file name, which may not contain path information or only contain relative paths. // For example: // test.pb ./common/test.pb // protobuf // test.fbs ./common/test.fbs // flatbuffers GetName() string // GetFullyQualifiedName has the same function as GetName. GetFullyQualifiedName() string // GetPackage returns the defined package name. // For protobuf, it is the definition corresponding to the package statement. // For flatbuffers, it is the definition corresponding to the namespace statement. // For example, // package trpc.testapp.testserver; // protobuf // namespace trpc.testapp.testserver; // flatbuffers GetPackage() string // GetFileOptions returns the file options defined in the pb file. // Usually, it will contain the package name information of the language itself. // For example, // // File option related to the go package of protobuf. // option go_package="trpc.group/trpcprotocol/testapp/testserver"; // // For flatbuffers, the functions that "file option" supported by extend the "attribute". // attribute "go_package=trpc.group/trpcprotocol/testapp/testserver"; GetFileOptions() FileOpt // GetDependencies returns the descriptor of the files that the current IDL depends on. // For protobuf, it is the files imported by the import statement. // For flatbuffers, it is the files included by the include statement. // For example, // import "common.proto"; // protobuf // include "common.fbs"; // flatbuffers GetDependencies() []Desc // GetServices returns the descriptor of all the RPC services defined in the file. GetServices() []ServiceDesc // GetMessageTypes returns the descriptor of all the messages defined in the file. GetMessageTypes() []MessageDesc }
Desc provides an abstract interface for the descriptors parsed from IDL. Currently, two types of IDLs are supported: protobuf and flatbuffers.
type FbsAttrs ¶
type FbsAttrs struct { Attrs []string KV map[string]string GoPackage *string `protobuf:"bytes,11,opt,name=go_package,json=goPackage" json:"go_package,omitempty"` }
FbsAttrs implements the FileOpt interface. Attrs contains various strings stored in the attribute field of flatbuffers. Among them, the following format is customized to provide go package information for flatbuffers files.
attribute "go_package=trpc.group/trpcprotocol/testapp/testserver"
func NewFbsAttrs ¶
NewFbsAttrs creates a new FbsAttrs object. During the creation process, it iterates over the attrs string list to generate key-value pairs.
func (*FbsAttrs) GetGoPackage ¶
GetGoPackage implements the FileOpt interface.
type FbsFileDescriptor ¶
type FbsFileDescriptor struct {
FD *fbs.SchemaDesc
}
FbsFileDescriptor implements the Desc interface and describes all information about a flatbuffers file.
func (*FbsFileDescriptor) GetDependencies ¶
func (p *FbsFileDescriptor) GetDependencies() []Desc
GetDependencies implements the Desc interface.
func (*FbsFileDescriptor) GetFileOptions ¶
func (p *FbsFileDescriptor) GetFileOptions() FileOpt
GetFileOptions implements the Desc interface.
func (*FbsFileDescriptor) GetFullyQualifiedName ¶
func (p *FbsFileDescriptor) GetFullyQualifiedName() string
GetFullyQualifiedName implements the Desc interface.
func (*FbsFileDescriptor) GetMessageTypes ¶
func (p *FbsFileDescriptor) GetMessageTypes() []MessageDesc
GetMessageTypes implements the Desc interface.
func (*FbsFileDescriptor) GetName ¶
func (p *FbsFileDescriptor) GetName() string
GetName implements the Desc interface.
func (*FbsFileDescriptor) GetPackage ¶
func (p *FbsFileDescriptor) GetPackage() string
GetPackage implements the Desc interface.
func (*FbsFileDescriptor) GetServices ¶
func (p *FbsFileDescriptor) GetServices() []ServiceDesc
GetServices implements the Desc interface.
type FbsMessageDescriptor ¶
FbsMessageDescriptor implements the MessageDesc interface.
func (*FbsMessageDescriptor) GetFile ¶
func (p *FbsMessageDescriptor) GetFile() Desc
GetFile implements the MessageDesc interface.
func (*FbsMessageDescriptor) GetFullyQualifiedName ¶
func (p *FbsMessageDescriptor) GetFullyQualifiedName() string
GetFullyQualifiedName implements the MessageDesc interface.
type FbsMethodDescriptor ¶
type FbsMethodDescriptor struct {
MD *fbs.MethodDesc
}
FbsMethodDescriptor implements the MethodDesc interface.
func (*FbsMethodDescriptor) GetInputType ¶
func (p *FbsMethodDescriptor) GetInputType() MessageDesc
GetInputType implements the MethodDesc interface.
func (*FbsMethodDescriptor) GetName ¶
func (p *FbsMethodDescriptor) GetName() string
GetName implements the MethodDesc interface.
func (*FbsMethodDescriptor) GetOutputType ¶
func (p *FbsMethodDescriptor) GetOutputType() MessageDesc
GetOutputType implements the MethodDesc interface.
func (*FbsMethodDescriptor) GetSourceInfo ¶
func (p *FbsMethodDescriptor) GetSourceInfo() SourceInfo
GetSourceInfo implements the MethodDesc interface.
func (*FbsMethodDescriptor) IsClientStreaming ¶
func (p *FbsMethodDescriptor) IsClientStreaming() bool
IsClientStreaming implements the MethodDesc interface.
func (*FbsMethodDescriptor) IsServerStreaming ¶
func (p *FbsMethodDescriptor) IsServerStreaming() bool
IsServerStreaming implements the MethodDesc interface.
type FbsServiceDescriptor ¶
FbsServiceDescriptor implements the ServiceDesc interface. Describes all information of an RPC service.
func (*FbsServiceDescriptor) GetMethods ¶
func (p *FbsServiceDescriptor) GetMethods() []MethodDesc
GetMethods implements the ServiceDesc interface.
func (*FbsServiceDescriptor) GetName ¶
func (p *FbsServiceDescriptor) GetName() string
GetName implements the ServiceDesc interface.
type FbsSourceInfo ¶
type FbsSourceInfo struct{}
FbsSourceInfo implements the SourceInfo interface.
func (*FbsSourceInfo) GetLeadingComments ¶
func (f *FbsSourceInfo) GetLeadingComments() string
GetLeadingComments implements the SourceInfo interface.
func (*FbsSourceInfo) GetTrailingComments ¶
func (f *FbsSourceInfo) GetTrailingComments() string
GetTrailingComments implements the SourceInfo interface.
type FileDescriptor ¶
type FileDescriptor struct { // FD is an interface for IDL, // such as *FileDescriptor parsed from protobuf and *FbsDescriptor parsed from flatbuffers. FD Desc FilePath string // Absolute path of the current file RelatvieFilePath string // Relatvie path from current executing directory. // Extracted from FD, it represents the package name of the IDL (protobuf or flatbuffers), e.g. trpc.$app.$server PackageName string // GoPackage is extracted from pb fileOption or fbs attribute, such as "trpc.group/.../helloworld" GoPackage string BaseGoPackageName string // BaseGoPackageName is usually the last part of GoPackage. AppName string // AppName is extracted from PackageName. ServerName string // ServerName is extracted from PackageName. // A pb file may import other pb files. // If there are references in the definition of RPC requests and responses, // the imported package name corresponding to the type is recorded. Imports []string ImportsX []ImportDesc FileOptions map[string]interface{} // KV pairs constructed by pb fileOptions or fbs attributes. Services []*ServiceDescriptor // Supports multiple services, extracted from pb service or fbs rpc_service. // The package name that let the key is pb file name and let the value is "protoc". Pb2ValidGoPkg map[string]string // The importpath in code that let key is pb file name and let value is "go". Pb2ImportPath map[string]string // pb file <-> its' deps proto files if any Pb2DepsPbs map[string][]string // The package name that let the key is pb file package directive and let the value is "protoc". Pkg2ValidGoPkg map[string]string // The importpath in code that let key is pb file package directive and let value is "go". Pkg2ImportPath map[string]string // RPCMessageType maps message type names to the filename where defined that type. RPCMessageType map[string]string // k is pkg.typ defined by pb, v is valid pkg.typ in go. }
FileDescriptor provides description information for the file scope of an IDL file.
func (*FileDescriptor) Dump ¶
func (fd *FileDescriptor) Dump()
Dump prints the protobuf file parsing information.
func (*FileDescriptor) ValidateEnabled ¶
func (fd *FileDescriptor) ValidateEnabled() bool
ValidateEnabled indicates whether the validate check is enabled or not.
type FileOpt ¶
type FileOpt interface { // GetGoPackage returns the value described by the go_package field. // For example, // // File option related to the "go package" of protobuf. // option go_package="trpc.group/trpcprotocol/testapp/testserver"; // // For flatbuffers, the functions that "file option" supported by extend the "attribute". // attribute "go_package=trpc.group/trpcprotocol/testapp/testserver"; GetGoPackage() string }
FileOpt provides an interface for file options. "file options" is a term in protobuf. This term is kept here for compatibility. The corresponding keyword in flatbuffers is "attribute". protobuf and flatbuffers have different implementations for this.
type ImportDesc ¶
ImportDesc provides an interface for parsing information related to "import" part (currently mainly used for Go).
type MessageDesc ¶
type MessageDesc interface { // GetFile returns the descriptor of the file in which this message is defined. GetFile() Desc // GetFullyQualifiedName returns the full name of this message. // Usually includes package information, such as "trpc.testapp.testserver.TestMessage". GetFullyQualifiedName() string }
MessageDesc provides an interface for describing messages in different IDLs.
type MethodDesc ¶
type MethodDesc interface { // GetName returns the name of the method. GetName() string // GetInputType returns the descriptor of the "request" type. GetInputType() MessageDesc // GetOutputType returns the descriptor of the "response" type. GetOutputType() MessageDesc // IsClientStreaming returns true if it is client streaming. IsClientStreaming() bool // IsServerStreaming returns true if it is server streaming. IsServerStreaming() bool // GetSourceInfo returns the comment information of this method in the source file. GetSourceInfo() SourceInfo }
MethodDesc provides an interface for describing methods for different IDLs.
type ProtoFileDescriptor ¶
type ProtoFileDescriptor struct {
FD *desc.FileDescriptor
}
ProtoFileDescriptor implements the Desc interface. Describes all information about a protobuf file.
func (*ProtoFileDescriptor) GetDependencies ¶
func (p *ProtoFileDescriptor) GetDependencies() []Desc
GetDependencies implements the Desc interface.
func (*ProtoFileDescriptor) GetFileOptions ¶
func (p *ProtoFileDescriptor) GetFileOptions() FileOpt
GetFileOptions implements the Desc interface.
func (*ProtoFileDescriptor) GetFullyQualifiedName ¶
func (p *ProtoFileDescriptor) GetFullyQualifiedName() string
GetFullyQualifiedName implements the Desc interface.
func (*ProtoFileDescriptor) GetMessageTypes ¶
func (p *ProtoFileDescriptor) GetMessageTypes() []MessageDesc
GetMessageTypes implements the Desc interface.
func (*ProtoFileDescriptor) GetName ¶
func (p *ProtoFileDescriptor) GetName() string
GetName implements the Desc interface.
func (*ProtoFileDescriptor) GetPackage ¶
func (p *ProtoFileDescriptor) GetPackage() string
GetPackage implements the Desc interface.
func (*ProtoFileDescriptor) GetServices ¶
func (p *ProtoFileDescriptor) GetServices() []ServiceDesc
GetServices implements the Desc interface.
type ProtoMessageDescriptor ¶
type ProtoMessageDescriptor struct {
MD *desc.MessageDescriptor
}
ProtoMessageDescriptor implements the MessageDesc interface.
func (*ProtoMessageDescriptor) GetFile ¶
func (p *ProtoMessageDescriptor) GetFile() Desc
GetFile implements the MessageDesc interface.
func (*ProtoMessageDescriptor) GetFullyQualifiedName ¶
func (p *ProtoMessageDescriptor) GetFullyQualifiedName() string
GetFullyQualifiedName implements the MessageDesc interface.
type ProtoMethodDescriptor ¶
type ProtoMethodDescriptor struct {
MD *desc.MethodDescriptor
}
ProtoMethodDescriptor implements the MethodDesc interface.
func (*ProtoMethodDescriptor) GetInputType ¶
func (p *ProtoMethodDescriptor) GetInputType() MessageDesc
GetInputType implements the MethodDesc interface.
func (*ProtoMethodDescriptor) GetName ¶
func (p *ProtoMethodDescriptor) GetName() string
GetName implements the MethodDesc interface.
func (*ProtoMethodDescriptor) GetOutputType ¶
func (p *ProtoMethodDescriptor) GetOutputType() MessageDesc
GetOutputType implements the MethodDesc interface.
func (*ProtoMethodDescriptor) GetSourceInfo ¶
func (p *ProtoMethodDescriptor) GetSourceInfo() SourceInfo
GetSourceInfo implements the MethodDesc interface.
func (*ProtoMethodDescriptor) IsClientStreaming ¶
func (p *ProtoMethodDescriptor) IsClientStreaming() bool
IsClientStreaming implements the MethodDesc interface.
func (*ProtoMethodDescriptor) IsServerStreaming ¶
func (p *ProtoMethodDescriptor) IsServerStreaming() bool
IsServerStreaming implements the MethodDesc interface.
type ProtoServiceDescriptor ¶
type ProtoServiceDescriptor struct {
SD *desc.ServiceDescriptor
}
ProtoServiceDescriptor implements the ServiceDesc interface. Describes all information of an RPC service.
func (*ProtoServiceDescriptor) GetMethods ¶
func (p *ProtoServiceDescriptor) GetMethods() []MethodDesc
GetMethods implements the ServiceDesc interface.
func (*ProtoServiceDescriptor) GetName ¶
func (p *ProtoServiceDescriptor) GetName() string
GetName implements the ServiceDesc interface.
type RESTfulAPIContent ¶
type RESTfulAPIContent struct { Method string PathTmpl string RequestBody string ResponseBody string }
RESTfulAPIContent is the content of a RESTful API.
type RESTfulAPIDescriptor ¶
type RESTfulAPIDescriptor struct {
ContentList []*RESTfulAPIContent // RESTful API content.
}
RESTfulAPIDescriptor is the description information required for generating stub code for RESTful APIs.
type RPCDescriptor ¶
type RPCDescriptor struct { Name string // Name of the RPC method. Cmd string // RPC command word. // FullyQualifiedCmd is the complete command word used for ServiceDesc and client requests. FullyQualifiedCmd string // RPC request message type, including package, such as package_a.TypeA RequestType string // RPC response message type, including package name, such as package_b.TypeB ResponseType string LeadingComments string // RPC leading comments. TrailingComments string // RPC trailing comments. SwaggerInfo SwaggerDescriptor // SwaggerDescriptor is used to generate swagger documentation. ServerStreaming bool // Used to determine if the RPC method is a server-side streaming. ClientStreaming bool // Used to determine if it's a client-side streaming. RequestTypeFileOptions map[string]interface{} ResponseTypeFileOptions map[string]interface{} RequestTypePkgDirective string ResponseTypePkgDirective string RESTfulAPIInfo RESTfulAPIDescriptor // Used for generating stub code related to RESTful APIs. }
RPCDescriptor provides the description information at the RPC level.
type ServiceDesc ¶
type ServiceDesc interface { // GetName returns the name of the RPC service. GetName() string // GetMethods returns the descriptor of all the methods defined in this RPC service. GetMethods() []MethodDesc }
ServiceDesc provides an interface for describing services for different IDLs.
type ServiceDescriptor ¶
type ServiceDescriptor struct { Name string // Service name. RPC []*RPCDescriptor // RPC interface definition. RPCx []*RPCDescriptor // RPC interface definition, including the RPC alias and original name. MethodRPC map[string]*RPCDescriptor // MethodRPC maps method name to RPC definition. MethodRPCx map[string][]*RPCDescriptor // MethodRPCx maps method name to RPCx definition which is actually aliases. }
ServiceDescriptor provides the description information at the service level.
type SourceInfo ¶
type SourceInfo interface { // GetLeadingComments returns the leading comments. GetLeadingComments() string // GetTrailingComments returns the trailing comments. GetTrailingComments() string }
SourceInfo provides an interface for source code comments in different IDLs.
type SwaggerDescriptor ¶
type SwaggerDescriptor struct { Title string // RPC method name. Method string // HTTP's method (if the method supports the HTTP protocol). Description string // Description of method. Params map[string]*SwaggerParamDescriptor // Description of the RPC parameters }
SwaggerDescriptor is the description information required for generating Swagger API documentation.
type SwaggerParamDescriptor ¶
SwaggerParamDescriptor is the description information for Swagger parameters.